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

# By Manuel Raynaud (8) and franck (2)
# Via franck
* 'master' of https://github.com/thelia/thelia:
  en_EN -> en_UK, the "en_EN" locale does not exists.
  Smarty inheritance in admin template.
  fix typo in phpdoc
  complete test for foramt_number smarty function
  test foramt_date without datetime object
  create foramt_number smarty function
  remove sqlmap file
  add some phpdoc
  complete test for format_date smarty function
  create new smarty function for displaying date in expected format

Conflicts:
	reset_install.sh
This commit is contained in:
gmorel
2013-09-04 12:01:12 +02:00
56 changed files with 3243 additions and 1526 deletions

View File

@@ -1,82 +0,0 @@
<?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\Coupon;
use Thelia\Core\Event\ActionEvent;
use Thelia\Model\Coupon;
/**
* Created by JetBrains PhpStorm.
* Date: 8/29/13
* Time: 3:45 PM
*
* Occurring when a Coupon is edited
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class CouponEditEvent extends ActionEvent
{
/** @var int Coupon being edited id */
protected $couponId;
/** @var Coupon Coupon being created */
protected $editedCoupon;
/**
* Constructor
*
* @param Coupon $coupon Coupon being edited
*/
public function __construct(Coupon $coupon)
{
$this->created_coupon = $coupon;
}
/**
* Modify Coupon being created
*
* @param Coupon $editedCoupon Coupon being created
*
* @return $this
*/
public function setCreatedCoupon(Coupon $editedCoupon)
{
$this->editedCoupon = $editedCoupon;
return $this;
}
/**
* Get Coupon being created
*
* @return Coupon
*/
public function getCreatedCoupon()
{
return clone $this->editedCoupon;
}
}

View File

@@ -22,8 +22,10 @@
/**********************************************************************************/
namespace Thelia\Core\Event\Coupon;
use Symfony\Component\EventDispatcher\Event;
use Thelia\Core\Event\ActionEvent;
use Thelia\Coupon\CouponRuleCollection;
use Thelia\Model\Coupon;
/**
* Created by JetBrains PhpStorm.
@@ -36,8 +38,11 @@ use Thelia\Coupon\CouponRuleCollection;
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class CouponCreateEvent extends ActionEvent
class CouponEvent extends ActionEvent
{
/** @var int Coupon Id */
protected $id = null;
/** @var CouponRuleCollection Array of CouponRuleInterface */
protected $rules = null;
@@ -74,6 +79,72 @@ class CouponCreateEvent extends ActionEvent
/** @var bool if Coupon is available for Products already on special offers */
protected $isAvailableOnSpecialOffers = false;
/** @var Coupon Coupon model */
protected $coupon = null;
/** @var string Coupon effect */
protected $effect;
/**
* Constructor
*
* @param string $code Coupon Code
* @param string $title Coupon title
* @param float $amount Amount removed from the Total Checkout
* @param string $effect Coupon effect
* @param string $shortDescription Coupon short description
* @param string $description Coupon description
* @param boolean $isEnabled Enable/Disable
* @param \DateTime $expirationDate Coupon expiration date
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
* @param boolean $isCumulative Is cumulative
* @param boolean $isRemovingPostage Is removing Postage
* @param int $maxUsage Coupon quantity
* @param CouponRuleCollection $rules CouponRuleInterface to add
* @param int $id Coupon id
*/
function __construct(
$code,
$title,
$amount,
$effect,
$shortDescription,
$description,
$isEnabled,
$expirationDate,
$isAvailableOnSpecialOffers,
$isCumulative,
$isRemovingPostage,
$maxUsage,
$rules,
$id = null
) {
$this->amount = $amount;
$this->code = $code;
$this->description = $description;
$this->expirationDate = $expirationDate;
$this->id = $id;
$this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers;
$this->isCumulative = $isCumulative;
$this->isEnabled = $isEnabled;
$this->isRemovingPostage = $isRemovingPostage;
$this->maxUsage = $maxUsage;
$this->rules = $rules;
$this->shortDescription = $shortDescription;
$this->title = $title;
$this->effect = $effect;
}
/**
* Return Coupon Id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Return Coupon code (ex: XMAS)
*
@@ -156,62 +227,6 @@ class CouponCreateEvent extends ActionEvent
return clone $this->rules;
}
/**
* Set effects generated by the coupon
*
* @param float $amount Amount removed from the Total Checkout
*
* @return $this
*/
public function setAmount($amount)
{
$this->amount = $amount;
return $this;
}
/**
* Set Coupon Code
*
* @param string $code Coupon Code
*
* @return $this
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* Set Coupon description
*
* @param string $description Coupon description
*
* @return $this
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Set Coupon expiration date (date given considered as expired)
*
* @param \DateTime $expirationDate Coupon expiration date
*
* @return $this
*/
public function setExpirationDate($expirationDate)
{
$this->expirationDate = $expirationDate;
return $this;
}
/**
* Return Coupon expiration date
*
@@ -222,20 +237,6 @@ class CouponCreateEvent extends ActionEvent
return clone $this->expirationDate;
}
/**
* Set if Coupon is available on special offers
*
* @param boolean $isAvailableOnSpecialOffers is available on special offers
*
* @return $this
*/
public function setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers)
{
$this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers;
return $this;
}
/**
* If Coupon is available on special offers
*
@@ -246,34 +247,6 @@ class CouponCreateEvent extends ActionEvent
return $this->isAvailableOnSpecialOffers;
}
/**
* Set if the Coupon is cumulative with other Coupons or not
*
* @param boolean $isCumulative is cumulative
*
* @return $this
*/
public function setIsCumulative($isCumulative)
{
$this->isCumulative = $isCumulative;
return $this;
}
/**
* Enable/Disable the Coupon
*
* @param boolean $isEnabled Enable/Disable
*
* @return $this
*/
public function setIsEnabled($isEnabled)
{
$this->isEnabled = $isEnabled;
return $this;
}
/**
* Get if Coupon is enabled or not
*
@@ -284,34 +257,6 @@ class CouponCreateEvent extends ActionEvent
return $this->isEnabled;
}
/**
* Set if Coupon is removing Postage
*
* @param boolean $isRemovingPostage is removing Postage
*
* @return $this
*/
public function setIsRemovingPostage($isRemovingPostage)
{
$this->isRemovingPostage = $isRemovingPostage;
return $this;
}
/**
* Set how many time a coupon can be used (-1 : unlimited)
*
* @param int $maxUsage Coupon quantity
*
* @return $this
*/
public function setMaxUsage($maxUsage)
{
$this->maxUsage = $maxUsage;
return $this;
}
/**
* Return how many time the Coupon can be used again
* Ex : -1 unlimited
@@ -324,51 +269,33 @@ class CouponCreateEvent extends ActionEvent
}
/**
* Replace the existing Rules by those given in parameter
* If one Rule is badly implemented, no Rule will be added
* Get Coupon effect
*
* @param CouponRuleCollection $rules CouponRuleInterface to add
*
* @return $this
* @throws \Thelia\Exception\InvalidRuleException
* @return string
*/
public function setRules(CouponRuleCollection $rules)
public function getEffect()
{
$this->rules = $rules;
$this->constraintManager = new ConstraintManager(
$this->adapter,
$this->rules
);
return $this->effect;
}
return $this;
/**
* @param \Thelia\Model\Coupon $coupon
*/
public function setCoupon($coupon)
{
$this->coupon = $coupon;
}
/**
* Set Coupon short description
*
* @param string $shortDescription Coupon short description
*
* @return $this
* @return \Thelia\Model\Coupon
*/
public function setShortDescription($shortDescription)
public function getCoupon()
{
$this->shortDescription = $shortDescription;
return $this;
return $this->coupon;
}
/**
* Set Coupon title
*
* @param string $title Coupon title
*
* @return $this
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
}

View File

@@ -0,0 +1,47 @@
<?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;
use Thelia\Model\Currency;
class CurrencyChangeEvent extends CurrencyCreateEvent
{
protected $currency_id;
public function __construct($currency_id)
{
$this->setCurrencyId($currency_id);
}
public function getCurrencyId()
{
return $this->currency_id;
}
public function setCurrencyId($currency_id)
{
$this->currency_id = $currency_id;
return $this;
}
}

View File

@@ -0,0 +1,93 @@
<?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;
use Thelia\Model\Currency;
class CurrencyCreateEvent extends CurrencyEvent
{
protected $currency_name;
protected $locale;
protected $symbol;
protected $code;
protected $rate;
// Use currency_name to prevent conflict with Event::name property.
public function getCurrencyName()
{
return $this->currency_name;
}
public function setCurrencyName($currency_name)
{
$this->currency_name = $currency_name;
return $this;
}
public function getLocale()
{
return $this->locale;
}
public function setLocale($locale)
{
$this->locale = $locale;
return $this;
}
public function getSymbol()
{
return $this->symbol;
}
public function setSymbol($symbol)
{
$this->symbol = $symbol;
}
public function getCode()
{
return $this->code;
}
public function setCode($code)
{
$this->code = $code;
return $this;
}
public function getRate()
{
return $this->rate;
}
public function setRate($rate)
{
$this->rate = $rate;
return $this;
}
}

View File

@@ -0,0 +1,48 @@
<?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;
use Thelia\Model\Currency;
class CurrencyDeleteEvent extends CurrencyEvent
{
protected $currency_id;
public function __construct($currency_id)
{
$this->setCurrencyId($currency_id);
}
public function getCurrencyId()
{
return $this->currency_id;
}
public function setCurrencyId($currency_id)
{
$this->currency_id = $currency_id;
return $this;
}
}

View File

@@ -0,0 +1,47 @@
<?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;
use Thelia\Model\Currency;
class CurrencyEvent extends ActionEvent
{
protected $currency;
public function __construct(Currency $currency = null)
{
$this->currency = $currency;
}
public function getCurrency()
{
return $this->currency;
}
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
}

View File

@@ -266,7 +266,6 @@ final class TheliaEvents
const BEFORE_DELETECONFIG = "action.before_deleteConfig";
const AFTER_DELETECONFIG = "action.after_deleteConfig";
// -- Messages management ---------------------------------------------
const MESSAGE_CREATE = "action.createMessage";
@@ -282,4 +281,18 @@ final class TheliaEvents
const BEFORE_DELETEMESSAGE = "action.before_deleteMessage";
const AFTER_DELETEMESSAGE = "action.after_deleteMessage";
// -- Currencies management ---------------------------------------------
const CURRENCY_CREATE = "action.createCurrency";
const CURRENCY_MODIFY = "action.changeCurrency";
const CURRENCY_DELETE = "action.deleteCurrency";
const BEFORE_CREATECURRENCY = "action.before_createCurrency";
const AFTER_CREATECURRENCY = "action.after_createCurrency";
const BEFORE_CHANGECURRENCY = "action.before_changeCurrency";
const AFTER_CHANGECURRENCY = "action.after_changeCurrency";
const BEFORE_DELETECURRENCY = "action.before_deleteCurrency";
const AFTER_DELETECURRENCY = "action.after_deleteCurrency";
}

View File

@@ -55,12 +55,15 @@ class Session extends BaseSession
return $this;
}
/**
* @return \Thelia\Model\Lang|null
*/
public function getLang()
{
return $this->get("lang", substr($this->getLocale(), 0, 2));
return $this->get("lang");
}
public function setLang($lang)
public function setLang(Lang $lang)
{
$this->set("lang", $lang);

View File

@@ -109,13 +109,13 @@ class Config extends BaseI18nLoop
->set("NAME" , $result->getName())
->set("VALUE" , $result->getValue())
->set("IS_TRANSLATED", $result->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale)
->set("LOCALE" , $locale)
->set("TITLE" , $result->getVirtualColumn('i18n_TITLE'))
->set("CHAPO" , $result->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION" , $result->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM" , $result->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("HIDDEN" , $result->getHidden())
->set("SECURED" , $result->getSecured())
->set("SECURED" , $result->getSecured())
->set("CREATE_DATE" , $result->getCreatedAt())
->set("UPDATE_DATE" , $result->getUpdatedAt())
;

View File

@@ -33,6 +33,8 @@ use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\CurrencyQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type\EnumListType;
/**
*
@@ -53,7 +55,22 @@ class Currency extends BaseI18nLoop
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('exclude'),
Argument::createBooleanTypeArgument('default_only', false)
Argument::createBooleanTypeArgument('default_only', false),
new Argument(
'order',
new TypeCollection(
new EnumListType(
array(
'id', 'id_reverse',
'name', 'name_reverse',
'code', 'code_reverse',
'symbol', 'symbol_reverse',
'rate', 'rate_reverse',
'manual', 'manual_reverse')
)
),
'manual'
)
);
}
@@ -87,7 +104,53 @@ class Currency extends BaseI18nLoop
$search->filterByByDefault(true);
}
$search->orderByPosition();
$orders = $this->getOrder();
foreach($orders as $order) {
switch ($order) {
case 'id':
$search->orderById(Criteria::ASC);
break;
case 'id_reverse':
$search->orderById(Criteria::DESC);
break;
case 'name':
$search->addAscendingOrderByColumn('i18n_NAME');
break;
case 'name_reverse':
$search->addDescendingOrderByColumn('i18n_NAME');
break;
case 'code':
$search->orderByCode(Criteria::ASC);
break;
case 'code_reverse':
$search->orderByCode(Criteria::DESC);
break;
case 'symbol':
$search->orderBySymbol(Criteria::ASC);
break;
case 'symbol_reverse':
$search->orderBySymbol(Criteria::DESC);
break;
case 'rate':
$search->orderByRate(Criteria::ASC);
break;
case 'rate_reverse':
$search->orderByRate(Criteria::DESC);
break;
case 'manual':
$search->orderByPosition(Criteria::ASC);
break;
case 'manual_reverse':
$search->orderByPosition(Criteria::DESC);
break;
}
}
/* perform search */
$currencies = $this->search($search, $pagination);
@@ -95,15 +158,18 @@ class Currency extends BaseI18nLoop
$loopResult = new LoopResult();
foreach ($currencies as $currency) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $currency->getId())
->set("IS_TRANSLATED",$currency->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale)
->set("NAME",$currency->getVirtualColumn('i18n_NAME'))
->set("ISOCODE", $currency->getCode())
->set("SYMBOL", $currency->getSymbol())
->set("RATE", $currency->getRate())
->set("IS_DEFAULT", $currency->getByDefault());
$loopResultRow
->set("ID" , $currency->getId())
->set("IS_TRANSLATED" , $currency->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale)
->set("NAME" , $currency->getVirtualColumn('i18n_NAME'))
->set("ISOCODE" , $currency->getCode())
->set("SYMBOL" , $currency->getSymbol())
->set("RATE" , $currency->getRate())
->set("POSITION" , $currency->getPosition())
->set("IS_DEFAULT" , $currency->getByDefault());
$loopResult->addRow($loopResultRow);
}

View File

@@ -50,6 +50,60 @@ class Image extends BaseI18nLoop
*/
protected $possible_sources = array('category', 'product', 'folder', 'content');
/**
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
$collection = new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('exclude'),
new Argument(
'order',
new TypeCollection(
new EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual-reverse', 'random'))
),
'manual'
),
Argument::createIntTypeArgument('lang'),
Argument::createIntTypeArgument('width'),
Argument::createIntTypeArgument('height'),
Argument::createIntTypeArgument('rotation', 0),
Argument::createAnyTypeArgument('background_color'),
Argument::createIntTypeArgument('quality'),
new Argument(
'resize_mode',
new TypeCollection(
new EnumType(array('crop', 'borders', 'none'))
),
'none'
),
Argument::createAnyTypeArgument('effects'),
Argument::createIntTypeArgument('category'),
Argument::createIntTypeArgument('product'),
Argument::createIntTypeArgument('folder'),
Argument::createIntTypeArgument('content'),
new Argument(
'source',
new TypeCollection(
new EnumType($this->possible_sources)
)
),
Argument::createIntTypeArgument('source_id')
);
// Add possible image sources
foreach($this->possible_sources as $source) {
$collection->addArgument(Argument::createIntTypeArgument($source));
}
return $collection;
}
/**
* Dynamically create the search query, and set the proper filter and order
*
@@ -244,19 +298,19 @@ class Image extends BaseI18nLoop
$loopResultRow = new LoopResultRow();
$loopResultRow
->set("ID", $result->getId())
->set("LOCALE",$locale)
->set("IMAGE_URL", $event->getFileUrl())
->set("ORIGINAL_IMAGE_URL", $event->getOriginalFileUrl())
->set("IMAGE_PATH", $event->getCacheFilepath())
->set("ORIGINAL_IMAGE_PATH", $source_filepath)
->set("TITLE",$folder->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $folder->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $folder->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $folder->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("POSITION", $result->getPosition())
->set("OBJECT_TYPE", $object_type)
->set("OBJECT_ID", $object_id)
->set("ID" , $result->getId())
->set("LOCALE" ,$locale)
->set("IMAGE_URL" , $event->getFileUrl())
->set("ORIGINAL_IMAGE_URL" , $event->getOriginalFileUrl())
->set("IMAGE_PATH" , $event->getCacheFilepath())
->set("ORIGINAL_IMAGE_PATH" , $source_filepath)
->set("TITLE" , $result->getVirtualColumn('i18n_TITLE'))
->set("CHAPO" , $result->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION" , $result->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM" , $result->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("POSITION" , $result->getPosition())
->set("OBJECT_TYPE" , $object_type)
->set("OBJECT_ID" , $object_id)
;
$loopResult->addRow($loopResultRow);
@@ -269,58 +323,4 @@ class Image extends BaseI18nLoop
return $loopResult;
}
/**
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
$collection = new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('exclude'),
new Argument(
'order',
new TypeCollection(
new EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual-reverse', 'random'))
),
'manual'
),
Argument::createIntTypeArgument('lang'),
Argument::createIntTypeArgument('width'),
Argument::createIntTypeArgument('height'),
Argument::createIntTypeArgument('rotation', 0),
Argument::createAnyTypeArgument('background_color'),
Argument::createIntTypeArgument('quality'),
new Argument(
'resize_mode',
new TypeCollection(
new EnumType(array('crop', 'borders', 'none'))
),
'none'
),
Argument::createAnyTypeArgument('effects'),
Argument::createIntTypeArgument('category'),
Argument::createIntTypeArgument('product'),
Argument::createIntTypeArgument('folder'),
Argument::createIntTypeArgument('content'),
new Argument(
'source',
new TypeCollection(
new EnumType($this->possible_sources)
)
),
Argument::createIntTypeArgument('source_id')
);
// Add possible image sources
foreach($this->possible_sources as $source) {
$collection->addArgument(Argument::createIntTypeArgument($source));
}
return $collection;
}
}

View File

@@ -0,0 +1,33 @@
<?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\Smarty\Exception;
/**
* Class SmartyPluginException
* @package Thelia\Core\Template\Smarty\Exception
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class SmartyPluginException extends \SmartyException
{}

View File

@@ -0,0 +1,154 @@
<?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\Smarty\Plugins;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Template\Smarty\Exception\SmartyPluginException;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
/**
*
* format_date and format_date smarty function.
*
* Class Format
* @package Thelia\Core\Template\Smarty\Plugins
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class Format extends AbstractSmartyPlugin
{
protected $request;
public function __construct(Request $request)
{
$this->request = $request;
}
/**
* return date in expected format
*
* available parameters :
* date => DateTime object (mandatory)
* format => expected format
* output => list of default system format. Values available :
* date => date format
* time => time format
* datetime => datetime format (default)
*
* ex :
* {format_date date=$dateTimeObject format="Y-m-d H:i:s"} will output the format with specific format
* {format_date date=$dateTimeObject output="date"} will output the date using the default date system format
* {format_date date=$dateTimeObject} will output with the default datetime system format
*
* @param array $params
* @param null $template
* @throws \Thelia\Core\Template\Smarty\Exception\SmartyPluginException
* @return string
*/
public function formatDate($params, $template = null)
{
if (array_key_exists("date", $params) === false) {
throw new SmartyPluginException("date is a mandatory parameter in format_date function");
}
$date = $params["date"];
if(!$date instanceof \DateTime) {
return "";
}
$format = null;
$output = array_key_exists("output", $params) ? $params["output"] : null;
if (array_key_exists("format", $params)) {
$format = $params["format"];
} else {
$session = $this->request->getSession();
$lang = $session->getLang();
if($lang) {
switch ($output) {
case "date" :
$format = $lang->getDateFormat();
break;
case "time" :
$format = $lang->getTimeFormat();
break;
default:
case "datetime" :
$format = $lang->getDateTimeFormat();
break;
}
}
}
return $date->format($format);
}
/**
*
* display numbers 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
*
* ex : {format_number number="1246.12" decimals="1" dec_point="," thousands_sep=" "} 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 formatNumber($params, $template = null)
{
if (array_key_exists("number", $params) === false) {
throw new SmartyPluginException("number is a mandatory parameter in format_number function");
}
$lang = $this->request->getSession()->getLang();
$number = $params["number"];
$decimals = array_key_exists("decimals", $params) ? $params["decimals"] : $lang->getDecimals();
$decPoint = array_key_exists("dec_point", $params) ? $params["dec_point"] : $lang->getDecimalSeparator();
$thousandsSep = array_key_exists("thousands_sep", $params) ? $params["thousands_sep"] : $lang->getThousandsSeparator();
return number_format($number, $decimals, $decPoint, $thousandsSep);
}
/**
* @return an array of SmartyPluginDescriptor
*/
public function getPluginDescriptors()
{
return array(
new SmartyPluginDescriptor("function", "format_date", $this, "formatDate"),
new SmartyPluginDescriptor("function", "format_number", $this, "formatNumber")
);
}
}

View File

@@ -126,7 +126,7 @@ class TheliaHttpKernel extends HttpKernel
if ($lang) {
$request->getSession()
->setLang($lang->getCode())
->setLang($lang)
->setLocale($lang->getLocale())
;
}