Merge branch 'master' into cart

This commit is contained in:
Manuel Raynaud
2013-08-07 09:44:34 +02:00
40 changed files with 1023 additions and 127 deletions

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\Event;
use Thelia\Model\Customer;
class CustomerEvent extends InternalEvent {
public $customer;
public function __construct(Customer $customer)
{
$this->customer = $customer;
}
}

View File

@@ -117,6 +117,9 @@ abstract class BaseLoop
$faultActor = array();
$faultDetails = array();
$loopType = isset($nameValuePairs['type']) ? $nameValuePairs['type'] : "undefined";
$loopName = isset($nameValuePairs['name']) ? $nameValuePairs['name'] : "undefined";
while (($argument = $this->args->current()) !== false) {
$this->args->next();
@@ -125,17 +128,17 @@ abstract class BaseLoop
/* check if mandatory */
if($value === null && $argument->mandatory) {
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('"%s" parameter is missing', $argument->name);
$faultDetails[] = sprintf('"%s" parameter is missing in loop type: %s, name: %s', $argument->name, $loopType, $loopName);
}
else if($value === '' && !$argument->empty) {
/* check if empty */
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('"%s" parameter cannot be empty', $argument->name);
$faultDetails[] = sprintf('"%s" parameter cannot be empty in loop type: %s, name: %s', $argument->name, $loopType, $loopName);
}
else if($value !== null && !$argument->type->isValid($value)) {
/* check type */
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('Invalid value for "%s" argument', $argument->name);
$faultDetails[] = sprintf('Invalid value for "%s" argument in loop type: %s, name: %s', $argument->name, $loopType, $loopName);
}
else {
/* set default */

View File

@@ -30,6 +30,8 @@ class LoopResultRow
public function set($key, $value)
{
$this->substitution[$key] = $value === null ? '' : $value;
return $this;
}
public function get($key)

View File

@@ -168,14 +168,25 @@ class Category extends BaseLoop
if ($this->not_empty && $category->countAllProducts() == 0) continue;
$loopResultRow = new LoopResultRow();
$loopResultRow->set("TITLE",$category->getTitle());
$loopResultRow->set("CHAPO", $category->getChapo());
$loopResultRow->set("DESCRIPTION", $category->getDescription());
$loopResultRow->set("POSTSCRIPTUM", $category->getPostscriptum());
$loopResultRow->set("PARENT", $category->getParent());
$loopResultRow->set("ID", $category->getId());
$loopResultRow->set("URL", $category->getUrl());
$loopResultRow->set("PRODUCT_COUNT", $category->countChild());
$loopResultRow
->set("ID", $category->getId())
->set("TITLE",$category->getTitle())
->set("CHAPO", $category->getChapo())
->set("DESCRIPTION", $category->getDescription())
->set("POSTSCRIPTUM", $category->getPostscriptum())
->set("PARENT", $category->getParent())
->set("URL", $category->getUrl())
->set("PRODUCT_COUNT", $category->countChild())
->set("VISIBLE", $category->getVisible() ? "1" : "0")
->set("POSITION", $category->getPosition())
->set("CREATE_DATE", $category->getCreatedAt())
->set("UPDATE_DATE", $category->getUpdatedAt())
->set("VERSION", $category->getVersion())
->set("VERSION_DATE", $category->getVersionCreatedAt())
->set("VERSION_AUTHOR", $category->getVersionCreatedBy())
;
$loopResult->addRow($loopResultRow);
}

View File

@@ -87,7 +87,7 @@ class FeatureValue extends BaseLoop
$search->filterByProductId($product, Criteria::EQUAL);
$featureAvailable = $this->geFeature_available();
$featureAvailable = $this->getFeature_available();
if (null !== $featureAvailable) {
$search->filterByFeatureAvId($featureAvailable, Criteria::IN);

View File

@@ -86,7 +86,7 @@ class Product extends BaseLoop
new TypeCollection(
new Type\EnumListType(array('alpha', 'alpha_reverse', /*'min_price', 'max_price',*/ 'manual', 'manual_reverse', 'ref', /*'promo', 'new',*/ 'random', 'given_id'))
),
'manual'
'alpha'
),
Argument::createIntListTypeArgument('exclude'),
Argument::createIntListTypeArgument('exclude_category'),
@@ -271,12 +271,12 @@ class Product extends BaseLoop
$search->orderBy('real_price', Criteria::DESC);
break;*/
case "manual":
if(null === $this->category || count($this->category) != 1)
if(null === $category || count($category) != 1)
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
$search->orderByPosition(Criteria::ASC);
break;
case "manual_reverse":
if(null === $this->category || count($this->category) != 1)
if(null === $category || count($category) != 1)
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
$search->orderByPosition(Criteria::DESC);
break;
@@ -395,17 +395,20 @@ class Product extends BaseLoop
foreach ($products as $product) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $product->getId());
$loopResultRow->set("REF",$product->getRef());
$loopResultRow->set("TITLE",$product->getTitle());
$loopResultRow->set("CHAPO", $product->getChapo());
$loopResultRow->set("DESCRIPTION", $product->getDescription());
$loopResultRow->set("POSTSCRIPTUM", $product->getPostscriptum());
//$loopResultRow->set("PRICE", $product->getPrice());
//$loopResultRow->set("PROMO_PRICE", $product->getPrice2());
//$loopResultRow->set("WEIGHT", $product->getWeight());
//$loopResultRow->set("PROMO", $product->getPromo());
//$loopResultRow->set("NEW", $product->getNewness());
$loopResultRow->set("ID", $product->getId())
->set("REF",$product->getRef())
->set("TITLE",$product->getTitle())
->set("CHAPO", $product->getChapo())
->set("DESCRIPTION", $product->getDescription())
->set("POSTSCRIPTUM", $product->getPostscriptum())
->set("PRICE", $product->getPrice())
->set("PROMO_PRICE", $product->getPrice2())
->set("WEIGHT", $product->getWeight())
->set("PROMO", $product->getPromo())
->set("NEW", $product->getNewness())
->set("POSITION", $product->getPosition())
;
$loopResult->addRow($loopResultRow);
}

View File

@@ -51,6 +51,48 @@ abstract class AbstractSmartyPlugin
return array();
}
/**
* Get a function or block parameter value, and normalize it, trimming balnks and
* making it lowercase
*
* @param array $params the parameters array
* @param mixed $name as single parameter name, or an array of names. In this case, the first defined parameter is returned. Use this for aliases (context, ctx, c)
* @param mixed $default the defaut value if parameter is missing (default to null)
* @return mixed the parameter value, or the default value if it is not found.
*/
public function getNormalizedParam($params, $name, $default = null)
{
$value = $this->getParam($params, $name, $default);
if (is_string($value)) $value = strtolower(trim($value));
return $value;
}
/**
* Get a function or block parameter value
*
* @param array $params the parameters array
* @param mixed $name as single parameter name, or an array of names. In this case, the first defined parameter is returned. Use this for aliases (context, ctx, c)
* @param mixed $default the defaut value if parameter is missing (default to null)
* @return mixed the parameter value, or the default value if it is not found.
*/
public function getParam($params, $name, $default = null)
{
if (is_array($name)) {
foreach($name as $test) {
if (isset($params[$test])) {
return $params[$test];
}
}
}
else if (isset($params[$name])) {
return $params[$name];
}
return $default;
}
/**
* @return an array of SmartyPluginDescriptor
*/

View File

@@ -78,13 +78,13 @@ class DataAccessFunctions extends AbstractSmartyPlugin
*/
protected function userDataAccess($objectLabel, $context, $params)
{
$attribute = $params['attr'];
$attribute = $this->getNormalizedParam($params, array('attribute', 'attrib', 'attr'));
if (! empty($attribute)) {
$user = $this->securityContext->setContext($context)->getUser();
if (null != $user) {
$getter = sprintf("get%s", ucfirst(strtolower($attribute)));
$getter = sprintf("get%s", ucfirst($attribute));
if (method_exists($user, $getter)) {
return $user->$getter();

View File

@@ -85,11 +85,13 @@ class Form extends AbstractSmartyPlugin
{
if ($repeat) {
if (empty($params['name'])) {
$name = $this->getParam($params, 'name');
if (null == $name) {
throw new \InvalidArgumentException("Missing 'name' parameter in form arguments");
}
$instance = $this->createInstance($params['name']);
$instance = $this->createInstance($name);
// Check if parser context contains our form
$errorForm = $this->parserContext->getErrorForm();
@@ -212,10 +214,11 @@ class Form extends AbstractSmartyPlugin
protected function getFormFieldView($params) {
$instance = $this->getInstanceFromParams($params);
if (! isset($params['field']))
$fieldName = $this->getParam($params, 'field');
if (null == $fieldName)
throw new \InvalidArgumentException("'field' parameter is missing");
$fieldName = $params['field'];
if (empty($instance->getView()[$fieldName]))
throw new \InvalidArgumentException(sprintf("Field name '%s' not found in form %s", $fieldName, $instance->getName()));
@@ -225,12 +228,12 @@ class Form extends AbstractSmartyPlugin
protected function getInstanceFromParams($params) {
if (empty($params['form'])) {
$instance = $this->getParam($params, 'form');
if (null == $instance) {
throw new \InvalidArgumentException("Missing 'form' parameter in form arguments");
}
$instance = $params["form"];
if (! $instance instanceof \Thelia\Form\BaseForm) {
throw new \InvalidArgumentException(sprintf("form parameter in form_field block must be an instance of
\Thelia\Form\BaseForm, instance of %s found", get_class($instance)));

View File

@@ -48,22 +48,25 @@ class Security extends AbstractSmartyPlugin
public function checkAuthFunction($params, &$smarty)
{
// Context: 'front' or 'admin'
$context = strtolower(trim($params['context']));
$context = $this->getNormalizedParam($params, 'context');
$this->securityContext->setContext($context);
$roles = $this->_explode($params['roles']);
$permissions = $this->_explode($params['permissions']);
$roles = $this->_explode($this->getParam($params, 'roles'));
$permissions = $this->_explode($this->getParam($params, 'permissions'));
if (! $this->securityContext->isGranted($roles, $permissions)) {
$ex = new AuthenticationException(
sprintf("User not granted for roles '%s', permissions '%s' in context '%s'.",
implode(',', $roles), implode(',', $permissions), $context
)
);
if (! empty($params['login_tpl'])) {
$ex->setLoginTemplate($params['login_tpl']);
$loginTpl = $this->getParam($params, 'login_tpl');
if (null != $loginTpl) {
$ex->setLoginTemplate($loginTpl);
}
throw $ex;
@@ -73,7 +76,7 @@ class Security extends AbstractSmartyPlugin
}
/**
* Define the various smarty plugins hendled by this class
* Define the various smarty plugins handled by this class
*
* @return an array of smarty plugin descriptors
*/

View File

@@ -71,9 +71,11 @@ class TheliaLoop extends AbstractSmartyPlugin
/**
* Process the count function: executes a loop and return the number of items found
*/
public function theliaCount($params, $template) {
public function theliaCount($params, $template)
{
$type = $this->getParam($params, 'type');
if (empty($params['type']))
if (null == $type)
throw new \InvalidArgumentException("Missing 'type' parameter in count arguments");
$loop = $this->createLoopInstance($params);
@@ -97,13 +99,15 @@ class TheliaLoop extends AbstractSmartyPlugin
*/
public function theliaLoop($params, $content, $template, &$repeat)
{
if (empty($params['name']))
$name = $this->getParam($params, 'name');
if (null == $name)
throw new \InvalidArgumentException("Missing 'name' parameter in loop arguments");
if (empty($params['type']))
throw new \InvalidArgumentException("Missing 'type' parameter in loop arguments");
$type = $this->getParam($params, 'type');
$name = $params['name'];
if (null == $type)
throw new \InvalidArgumentException("Missing 'type' parameter in loop arguments");
if ($content === null) {
// Check if a loop with the same name exists in the current scope, and abort if it's the case.
@@ -116,8 +120,12 @@ class TheliaLoop extends AbstractSmartyPlugin
self::$pagination[$name] = null;
$loopResults = $loop->exec(self::$pagination[$name]);
$this->loopstack[$name] = $loopResults;
// Pas de résultat ? la boucle est terminée, ne pas évaluer le contenu.
if ($loopResults->isEmpty()) $repeat = false;
} else {
$loopResults = $this->loopstack[$name];
@@ -223,10 +231,10 @@ class TheliaLoop extends AbstractSmartyPlugin
*/
public function theliaPageLoop($params, $content, $template, &$repeat)
{
if (empty($params['rel']))
throw new \InvalidArgumentException("Missing 'rel' parameter in page loop");
$loopName = $this->getParam($params, 'rel');
$loopName = $params['rel'];
if (null == $loopName)
throw new \InvalidArgumentException("Missing 'rel' parameter in page loop");
// Find loop results in the current template vars
/* $loopResults = $template->getTemplateVars($loopName);
@@ -274,11 +282,10 @@ class TheliaLoop extends AbstractSmartyPlugin
*/
protected function checkEmptyLoop($params, $template)
{
$loopName = $this->getParam($params, 'rel');
if (empty($params['rel']))
throw new \InvalidArgumentException("Missing 'rel' parameter in ifloop/elseloop arguments");
$loopName = $params['rel'];
if (null == $loopName)
throw new \InvalidArgumentException("Missing 'rel' parameter in ifloop/elseloop arguments");
if (! isset($this->loopstack[$loopName])) {
throw new \InvalidArgumentException("Loop $loopName is not defined.");

View File

@@ -49,10 +49,10 @@ class Translation extends AbstractSmartyPlugin
$vars = array();
foreach($params as $name => $value) {
$vars["%$name"] = $value;
if ($name != 'l') $vars["%$name"] = $value;
}
return $this->translator->trans($params['l'], $vars);
return $this->translator->trans($this->getParam($params, 'l'), $vars);
}
/**

View File

@@ -47,7 +47,7 @@ class UrlGenerator extends AbstractSmartyPlugin
public function generateUrlFunction($params, &$smarty)
{
// the path to process
$path = trim($params['path']);
$path = $this->getParam($params, 'path');
return URL::absoluteUrl($path, $this->getArgsFromParam($params));
}
@@ -59,19 +59,36 @@ class UrlGenerator extends AbstractSmartyPlugin
* @param unknown $smarty
* @return string no text is returned.
*/
public function generateViewUrlFunction($params, &$smarty)
public function generateFrontViewUrlFunction($params, &$smarty)
{
return $this->generateViewUrlFunction($params, false);
}
/**
* Process administration view url generator function
*
* @param array $params
* @param unknown $smarty
* @return string no text is returned.
*/
public function generateAdminViewUrlFunction($params, &$smarty)
{
return $this->generateViewUrlFunction($params, true);
}
protected function generateViewUrlFunction($params, $forAdmin)
{
// the view name (without .html)
$view = trim($params['view']);
$view = $this->getParam($params,'view');
// the related action (optionale)
$action = trim($params['action']);
$action = $this->getParam($params, 'action');
$args = $this->getArgsFromParam($params);
if (! empty($action)) $args['action'] = $action;
return URL::viewUrl($view, $args);
return $forAdmin ? URL::adminViewUrl($view, $args) : URL::viewUrl($view, $args);
}
/**
@@ -83,14 +100,13 @@ class UrlGenerator extends AbstractSmartyPlugin
*/
private function getArgsFromParam($params) {
if (isset($params['args']))
return explode($params['args'], ',');
$args = $this->getParam($params, array('arguments', 'args'));
return array();
return $args !== null ? explode($args, ',') : array();
}
/**
* Define the various smarty plugins hendled by this class
* Define the various smarty plugins handled by this class
*
* @return an array of smarty plugin descriptors
*/
@@ -98,7 +114,8 @@ class UrlGenerator extends AbstractSmartyPlugin
{
return array(
new SmartyPluginDescriptor('function', 'url', $this, 'generateUrlFunction'),
new SmartyPluginDescriptor('function', 'viewurl', $this, 'generateViewUrlFunction')
new SmartyPluginDescriptor('function', 'viewurl', $this, 'generateFrontViewUrlFunction'),
new SmartyPluginDescriptor('function', 'admin_viewurl', $this, 'generateAdminViewUrlFunction')
);
}
}