apply cs-fixer
This commit is contained in:
@@ -22,15 +22,12 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Action;
|
namespace Thelia\Action;
|
||||||
|
|
||||||
|
|
||||||
use Thelia\Form\BaseForm;
|
use Thelia\Form\BaseForm;
|
||||||
use Thelia\Action\Exception\FormValidationException;
|
use Thelia\Action\Exception\FormValidationException;
|
||||||
use Thelia\Core\Event\ActionEvent;
|
use Thelia\Core\Event\ActionEvent;
|
||||||
use Symfony\Component\Form\Form;
|
use Symfony\Component\Form\Form;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BaseAction
|
class BaseAction
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -39,16 +36,17 @@ class BaseAction
|
|||||||
*/
|
*/
|
||||||
protected $container;
|
protected $container;
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container) {
|
public function __construct(ContainerInterface $container)
|
||||||
|
{
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate a BaseForm
|
* Validate a BaseForm
|
||||||
*
|
*
|
||||||
* @param BaseForm $aBaseForm the form
|
* @param BaseForm $aBaseForm the form
|
||||||
* @param string $expectedMethod the expected method, POST or GET, or null for any of them
|
* @param string $expectedMethod the expected method, POST or GET, or null for any of them
|
||||||
* @throws FormValidationException is the form contains error, or the method is not the right one
|
* @throws FormValidationException is the form contains error, or the method is not the right one
|
||||||
* @return \Symfony\Component\Form\Form Form the symfony form object
|
* @return \Symfony\Component\Form\Form Form the symfony form object
|
||||||
*/
|
*/
|
||||||
protected function validateForm(BaseForm $aBaseForm, $expectedMethod = null)
|
protected function validateForm(BaseForm $aBaseForm, $expectedMethod = null)
|
||||||
@@ -60,14 +58,11 @@ class BaseAction
|
|||||||
$form->bind($aBaseForm->getRequest());
|
$form->bind($aBaseForm->getRequest());
|
||||||
|
|
||||||
if ($form->isValid()) {
|
if ($form->isValid()) {
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new FormValidationException("Missing or invalid data");
|
throw new FormValidationException("Missing or invalid data");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new FormValidationException(sprintf("Wrong form method, %s expected.", $expectedMethod));
|
throw new FormValidationException(sprintf("Wrong form method, %s expected.", $expectedMethod));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,12 +70,12 @@ class BaseAction
|
|||||||
/**
|
/**
|
||||||
* Propagate a form error in the action event
|
* Propagate a form error in the action event
|
||||||
*
|
*
|
||||||
* @param BaseForm $aBaseForm the form
|
* @param BaseForm $aBaseForm the form
|
||||||
* @param string $error_message an error message that may be displayed to the customer
|
* @param string $error_message an error message that may be displayed to the customer
|
||||||
* @param ActionEvent $event the action event
|
* @param ActionEvent $event the action event
|
||||||
*/
|
*/
|
||||||
protected function propagateFormError(BaseForm $aBaseForm, $error_message, ActionEvent $event) {
|
protected function propagateFormError(BaseForm $aBaseForm, $error_message, ActionEvent $event)
|
||||||
|
{
|
||||||
// The form has an error
|
// The form has an error
|
||||||
$aBaseForm->setError(true);
|
$aBaseForm->setError(true);
|
||||||
$aBaseForm->setErrorMessage($error_message);
|
$aBaseForm->setErrorMessage($error_message);
|
||||||
@@ -102,4 +97,4 @@ class BaseAction
|
|||||||
return $this->container->get('event_dispatcher');
|
return $this->container->get('event_dispatcher');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,8 @@ namespace Thelia\Action;
|
|||||||
|
|
||||||
use Propel\Runtime\Exception\PropelException;
|
use Propel\Runtime\Exception\PropelException;
|
||||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Thelia\Core\Event\ActionEvent;
|
|
||||||
use Thelia\Core\Event\CartEvent;
|
use Thelia\Core\Event\CartEvent;
|
||||||
use Thelia\Form\CartAdd;
|
use Thelia\Form\CartAdd;
|
||||||
use Thelia\Model\ProductPrice;
|
use Thelia\Model\ProductPrice;
|
||||||
@@ -92,14 +90,13 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
|
|
||||||
$message = $e->getMessage();
|
$message = $e->getMessage();
|
||||||
}
|
}
|
||||||
if($message) {
|
if ($message) {
|
||||||
// The form has errors, propagate it.
|
// The form has errors, propagate it.
|
||||||
$this->propagateFormError($cartAdd, $message, $event);
|
$this->propagateFormError($cartAdd, $message, $event);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Delete specify article present into cart
|
* Delete specify article present into cart
|
||||||
@@ -184,13 +181,11 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* increase the quantity for an existing cartItem
|
* increase the quantity for an existing cartItem
|
||||||
*
|
*
|
||||||
* @param CartItem $cartItem
|
* @param CartItem $cartItem
|
||||||
* @param float $quantity
|
* @param float $quantity
|
||||||
*/
|
*/
|
||||||
protected function updateQuantity(CartItem $cartItem, $quantity)
|
protected function updateQuantity(CartItem $cartItem, $quantity)
|
||||||
{
|
{
|
||||||
@@ -203,10 +198,10 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
* try to attach a new item to an existing cart
|
* try to attach a new item to an existing cart
|
||||||
*
|
*
|
||||||
* @param \Thelia\Model\Cart $cart
|
* @param \Thelia\Model\Cart $cart
|
||||||
* @param int $productId
|
* @param int $productId
|
||||||
* @param int $productSaleElementsId
|
* @param int $productSaleElementsId
|
||||||
* @param float $quantity
|
* @param float $quantity
|
||||||
* @param ProductPrice $productPrice
|
* @param ProductPrice $productPrice
|
||||||
*/
|
*/
|
||||||
protected function addItem(\Thelia\Model\Cart $cart, $productId, $productSaleElementsId, $quantity, ProductPrice $productPrice)
|
protected function addItem(\Thelia\Model\Cart $cart, $productId, $productSaleElementsId, $quantity, ProductPrice $productPrice)
|
||||||
{
|
{
|
||||||
@@ -227,9 +222,9 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
* find a specific record in CartItem table using the Cart id, the product id
|
* find a specific record in CartItem table using the Cart id, the product id
|
||||||
* and the product_sale_elements id
|
* and the product_sale_elements id
|
||||||
*
|
*
|
||||||
* @param int $cartId
|
* @param int $cartId
|
||||||
* @param int $productId
|
* @param int $productId
|
||||||
* @param int $productSaleElementsId
|
* @param int $productSaleElementsId
|
||||||
* @return ChildCartItem
|
* @return ChildCartItem
|
||||||
*/
|
*/
|
||||||
protected function findItem($cartId, $productId, $productSaleElementsId)
|
protected function findItem($cartId, $productId, $productSaleElementsId)
|
||||||
@@ -244,7 +239,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
/**
|
/**
|
||||||
* Find the good way to construct the cart form
|
* Find the good way to construct the cart form
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return CartAdd
|
* @return CartAdd
|
||||||
*/
|
*/
|
||||||
private function getAddCartForm(Request $request)
|
private function getAddCartForm(Request $request)
|
||||||
|
|||||||
@@ -40,15 +40,14 @@ use Propel\Runtime\Propel;
|
|||||||
use Thelia\Model\Map\CategoryTableMap;
|
use Thelia\Model\Map\CategoryTableMap;
|
||||||
use Propel\Runtime\Exception\PropelException;
|
use Propel\Runtime\Exception\PropelException;
|
||||||
|
|
||||||
|
|
||||||
class Category extends BaseAction implements EventSubscriberInterface
|
class Category extends BaseAction implements EventSubscriberInterface
|
||||||
{
|
{
|
||||||
public function create(ActionEvent $event)
|
public function create(ActionEvent $event)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->checkAuth("ADMIN", "admin.category.create");
|
$this->checkAuth("ADMIN", "admin.category.create");
|
||||||
|
|
||||||
$request = $event->getRequest();
|
$request = $event->getRequest();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$categoryCreationForm = new CategoryCreationForm($request);
|
$categoryCreationForm = new CategoryCreationForm($request);
|
||||||
@@ -92,7 +91,7 @@ class Category extends BaseAction implements EventSubscriberInterface
|
|||||||
public function modify(ActionEvent $event)
|
public function modify(ActionEvent $event)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->checkAuth("ADMIN", "admin.category.delete");
|
$this->checkAuth("ADMIN", "admin.category.delete");
|
||||||
|
|
||||||
$request = $event->getRequest();
|
$request = $event->getRequest();
|
||||||
|
|
||||||
@@ -163,9 +162,9 @@ class Category extends BaseAction implements EventSubscriberInterface
|
|||||||
public function delete(ActionEvent $event)
|
public function delete(ActionEvent $event)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->checkAuth("ADMIN", "admin.category.delete");
|
$this->checkAuth("ADMIN", "admin.category.delete");
|
||||||
|
|
||||||
$request = $event->getRequest();
|
$request = $event->getRequest();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$categoryDeletionForm = new CategoryDeletionForm($request);
|
$categoryDeletionForm = new CategoryDeletionForm($request);
|
||||||
@@ -214,11 +213,11 @@ class Category extends BaseAction implements EventSubscriberInterface
|
|||||||
public function toggleVisibility(ActionEvent $event)
|
public function toggleVisibility(ActionEvent $event)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->checkAuth("ADMIN", "admin.category.edit");
|
$this->checkAuth("ADMIN", "admin.category.edit");
|
||||||
|
|
||||||
$request = $event->getRequest();
|
$request = $event->getRequest();
|
||||||
|
|
||||||
$category = CategoryQuery::create()->findPk($request->get('category_id', 0));
|
$category = CategoryQuery::create()->findPk($request->get('category_id', 0));
|
||||||
|
|
||||||
if ($category !== null) {
|
if ($category !== null) {
|
||||||
|
|
||||||
@@ -237,8 +236,9 @@ class Category extends BaseAction implements EventSubscriberInterface
|
|||||||
*
|
*
|
||||||
* @param ActionEvent $event
|
* @param ActionEvent $event
|
||||||
*/
|
*/
|
||||||
public function changePositionUp(ActionEvent $event) {
|
public function changePositionUp(ActionEvent $event)
|
||||||
return $this->exchangePosition($event, 'up');
|
{
|
||||||
|
return $this->exchangePosition($event, 'up');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,67 +246,65 @@ class Category extends BaseAction implements EventSubscriberInterface
|
|||||||
*
|
*
|
||||||
* @param ActionEvent $event
|
* @param ActionEvent $event
|
||||||
*/
|
*/
|
||||||
public function changePositionDown(ActionEvent $event) {
|
public function changePositionDown(ActionEvent $event)
|
||||||
return $this->exchangePosition($event, 'down');
|
{
|
||||||
|
return $this->exchangePosition($event, 'down');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move up or down a category
|
* Move up or down a category
|
||||||
*
|
*
|
||||||
* @param ActionEvent $event
|
* @param ActionEvent $event
|
||||||
* @param string $direction up to move up, down to move down
|
* @param string $direction up to move up, down to move down
|
||||||
*/
|
*/
|
||||||
protected function exchangePosition(ActionEvent $event, $direction) {
|
protected function exchangePosition(ActionEvent $event, $direction)
|
||||||
|
{
|
||||||
|
$this->checkAuth("ADMIN", "admin.category.edit");
|
||||||
|
|
||||||
$this->checkAuth("ADMIN", "admin.category.edit");
|
$request = $event->getRequest();
|
||||||
|
|
||||||
$request = $event->getRequest();
|
$category = CategoryQuery::create()->findPk($request->get('category_id', 0));
|
||||||
|
|
||||||
$category = CategoryQuery::create()->findPk($request->get('category_id', 0));
|
if ($category !== null) {
|
||||||
|
|
||||||
if ($category !== null) {
|
// The current position of the category
|
||||||
|
$my_position = $category->getPosition();
|
||||||
|
|
||||||
// The current position of the category
|
// Find category to exchange position with
|
||||||
$my_position = $category->getPosition();
|
$search = CategoryQuery::create()
|
||||||
|
->filterByParent($category->getParent());
|
||||||
|
|
||||||
// Find category to exchange position with
|
// Up or down ?
|
||||||
$search = CategoryQuery::create()
|
if ($direction == 'up') {
|
||||||
->filterByParent($category->getParent());
|
// Find the category immediately before me
|
||||||
|
$search->filterByPosition(array('max' => $my_position-1))->orderByPosition(Criteria::DESC);
|
||||||
|
} elseif ($direction == 'down') {
|
||||||
|
// Find the category immediately after me
|
||||||
|
$search->filterByPosition(array('min' => $my_position+1))->orderByPosition(Criteria::ASC);
|
||||||
|
} else
|
||||||
|
|
||||||
// Up or down ?
|
return;
|
||||||
if ($direction == 'up') {
|
|
||||||
// Find the category immediately before me
|
|
||||||
$search->filterByPosition(array('max' => $my_position-1))->orderByPosition(Criteria::DESC);
|
|
||||||
}
|
|
||||||
else if ($direction == 'down') {
|
|
||||||
// Find the category immediately after me
|
|
||||||
$search->filterByPosition(array('min' => $my_position+1))->orderByPosition(Criteria::ASC);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
|
|
||||||
$result = $search->findOne();
|
$result = $search->findOne();
|
||||||
|
|
||||||
|
// If we found the proper category, exchange their positions
|
||||||
|
if ($result) {
|
||||||
|
|
||||||
// If we found the proper category, exchange their positions
|
$cnx = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME);
|
||||||
if ($result) {
|
|
||||||
|
|
||||||
$cnx = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME);
|
$cnx->beginTransaction();
|
||||||
|
|
||||||
$cnx->beginTransaction();
|
try {
|
||||||
|
$category->setPosition($result->getPosition())->save();
|
||||||
|
|
||||||
try {
|
$result->setPosition($my_position)->save();
|
||||||
$category->setPosition($result->getPosition())->save();
|
|
||||||
|
|
||||||
$result->setPosition($my_position)->save();
|
$cnx->commit();
|
||||||
|
} catch (Exception $e) {
|
||||||
$cnx->commit();
|
$cnx->rollback();
|
||||||
}
|
}
|
||||||
catch(Exception $e) {
|
}
|
||||||
$cnx->rollback();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -314,61 +312,59 @@ class Category extends BaseAction implements EventSubscriberInterface
|
|||||||
*
|
*
|
||||||
* @param ActionEvent $event
|
* @param ActionEvent $event
|
||||||
*/
|
*/
|
||||||
public function changePosition(ActionEvent $event) {
|
public function changePosition(ActionEvent $event)
|
||||||
|
{
|
||||||
|
$this->checkAuth("ADMIN", "admin.category.edit");
|
||||||
|
|
||||||
$this->checkAuth("ADMIN", "admin.category.edit");
|
$request = $event->getRequest();
|
||||||
|
|
||||||
$request = $event->getRequest();
|
$category = CategoryQuery::create()->findPk($request->get('category_id', 0));
|
||||||
|
|
||||||
$category = CategoryQuery::create()->findPk($request->get('category_id', 0));
|
if ($category !== null) {
|
||||||
|
|
||||||
if ($category !== null) {
|
// The required position
|
||||||
|
$new_position = $request->get('position', null);
|
||||||
|
|
||||||
// The required position
|
// The current position
|
||||||
$new_position = $request->get('position', null);
|
$current_position = $category->getPosition();
|
||||||
|
|
||||||
// The current position
|
if ($new_position != null && $new_position > 0 && $new_position != $current_position) {
|
||||||
$current_position = $category->getPosition();
|
|
||||||
|
|
||||||
if ($new_position != null && $new_position > 0 && $new_position != $current_position) {
|
// Find categories to offset
|
||||||
|
$search = CategoryQuery::create()->filterByParent($category->getParent());
|
||||||
|
|
||||||
// Find categories to offset
|
if ($new_position > $current_position) {
|
||||||
$search = CategoryQuery::create()->filterByParent($category->getParent());
|
// The new position is after the current position -> we will offset + 1 all categories located between us and the new position
|
||||||
|
$search->filterByPosition(array('min' => 1+$current_position, 'max' => $new_position));
|
||||||
|
|
||||||
if ($new_position > $current_position) {
|
$delta = -1;
|
||||||
// The new position is after the current position -> we will offset + 1 all categories located between us and the new position
|
} else {
|
||||||
$search->filterByPosition(array('min' => 1+$current_position, 'max' => $new_position));
|
// The new position is brefore the current position -> we will offset - 1 all categories located between us and the new position
|
||||||
|
$search->filterByPosition(array('min' => $new_position, 'max' => $current_position - 1));
|
||||||
|
|
||||||
$delta = -1;
|
$delta = 1;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// The new position is brefore the current position -> we will offset - 1 all categories located between us and the new position
|
|
||||||
$search->filterByPosition(array('min' => $new_position, 'max' => $current_position - 1));
|
|
||||||
|
|
||||||
$delta = 1;
|
$results = $search->find();
|
||||||
}
|
|
||||||
|
|
||||||
$results = $search->find();
|
$cnx = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME);
|
||||||
|
|
||||||
$cnx = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME);
|
$cnx->beginTransaction();
|
||||||
|
|
||||||
$cnx->beginTransaction();
|
try {
|
||||||
|
foreach ($results as $result) {
|
||||||
|
$result->setPosition($result->getPosition() + $delta)->save($cnx);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
$category->setPosition($new_position)->save($cnx);
|
||||||
foreach($results as $result) {
|
|
||||||
$result->setPosition($result->getPosition() + $delta)->save($cnx);
|
|
||||||
}
|
|
||||||
|
|
||||||
$category->setPosition($new_position)->save($cnx);
|
$cnx->commit();
|
||||||
|
} catch (Exception $e) {
|
||||||
$cnx->commit();
|
$cnx->rollback();
|
||||||
}
|
}
|
||||||
catch(Exception $e) {
|
}
|
||||||
$cnx->rollback();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of event names this subscriber listens to.
|
* Returns an array of event names this subscriber listens to.
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ namespace Thelia\Action;
|
|||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Thelia\Core\Event\ActionEvent;
|
use Thelia\Core\Event\ActionEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
use Thelia\Form\BaseForm;
|
|
||||||
use Thelia\Form\CustomerCreation;
|
use Thelia\Form\CustomerCreation;
|
||||||
use Thelia\Form\CustomerModification;
|
use Thelia\Form\CustomerModification;
|
||||||
use Thelia\Model\Customer as CustomerModel;
|
use Thelia\Model\Customer as CustomerModel;
|
||||||
@@ -34,7 +33,6 @@ use Thelia\Log\Tlog;
|
|||||||
use Thelia\Model\CustomerQuery;
|
use Thelia\Model\CustomerQuery;
|
||||||
use Thelia\Form\CustomerLogin;
|
use Thelia\Form\CustomerLogin;
|
||||||
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
|
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
|
||||||
use Thelia\Core\Security\SecurityContext;
|
|
||||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||||
use Thelia\Core\Security\Exception\UsernameNotFoundException;
|
use Thelia\Core\Security\Exception\UsernameNotFoundException;
|
||||||
@@ -122,7 +120,6 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
|||||||
$this->processSuccessfullLogin($event, $customer, $customerModification);
|
$this->processSuccessfullLogin($event, $customer, $customerModification);
|
||||||
} catch (PropelException $e) {
|
} catch (PropelException $e) {
|
||||||
|
|
||||||
|
|
||||||
Tlog::getInstance()->error(sprintf('error during modifying customer on action/modifyCustomer with message "%s"', $e->getMessage()));
|
Tlog::getInstance()->error(sprintf('error during modifying customer on action/modifyCustomer with message "%s"', $e->getMessage()));
|
||||||
|
|
||||||
$message = "Failed to change your account, please try again.";
|
$message = "Failed to change your account, please try again.";
|
||||||
@@ -144,8 +141,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
|||||||
{
|
{
|
||||||
$event->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_LOGOUT, $event);
|
$event->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_LOGOUT, $event);
|
||||||
|
|
||||||
|
$this->getFrontSecurityContext()->clear();
|
||||||
$this->getFrontSecurityContext()->clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,10 +22,6 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Cart;
|
namespace Thelia\Cart;
|
||||||
|
|
||||||
use Thelia\Model\ProductPrice;
|
|
||||||
use Thelia\Model\ProductPriceQuery;
|
|
||||||
use Thelia\Model\CartItem;
|
|
||||||
use Thelia\Model\CartItemQuery;
|
|
||||||
use Thelia\Model\CartQuery;
|
use Thelia\Model\CartQuery;
|
||||||
use Thelia\Model\Cart as CartModel;
|
use Thelia\Model\Cart as CartModel;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
@@ -35,18 +31,19 @@ use Thelia\Core\HttpFoundation\Session\Session;
|
|||||||
use Thelia\Core\Event\Internal\CartEvent;
|
use Thelia\Core\Event\Internal\CartEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
|
|
||||||
trait CartTrait {
|
trait CartTrait
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* search if cart already exists in session. If not try to create a new one or duplicate an old one.
|
* search if cart already exists in session. If not try to create a new one or duplicate an old one.
|
||||||
*
|
*
|
||||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||||
* @return \Thelia\Model\Cart
|
* @return \Thelia\Model\Cart
|
||||||
*/
|
*/
|
||||||
public function getCart(Request $request)
|
public function getCart(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(null !== $cart = $request->getSession()->getCart()){
|
if (null !== $cart = $request->getSession()->getCart()) {
|
||||||
return $cart;
|
return $cart;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +58,7 @@ trait CartTrait {
|
|||||||
$customer = $request->getSession()->getCustomerUser();
|
$customer = $request->getSession()->getCustomerUser();
|
||||||
|
|
||||||
if ($customer) {
|
if ($customer) {
|
||||||
if($cart->getCustomerId() != $customer->getId()) {
|
if ($cart->getCustomerId() != $customer->getId()) {
|
||||||
//le customer du panier n'est pas le mm que celui connecté, il faut cloner le panier sans le customer_id
|
//le customer du panier n'est pas le mm que celui connecté, il faut cloner le panier sans le customer_id
|
||||||
$cart = $this->duplicateCart($cart, $request->getSession(), $customer);
|
$cart = $this->duplicateCart($cart, $request->getSession(), $customer);
|
||||||
}
|
}
|
||||||
@@ -84,7 +81,7 @@ trait CartTrait {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Thelia\Core\HttpFoundation\Session\Session $session
|
* @param \Thelia\Core\HttpFoundation\Session\Session $session
|
||||||
* @return \Thelia\Model\Cart
|
* @return \Thelia\Model\Cart
|
||||||
*/
|
*/
|
||||||
protected function createCart(Session $session)
|
protected function createCart(Session $session)
|
||||||
@@ -92,7 +89,7 @@ trait CartTrait {
|
|||||||
$cart = new CartModel();
|
$cart = new CartModel();
|
||||||
$cart->setToken($this->generateCookie());
|
$cart->setToken($this->generateCookie());
|
||||||
|
|
||||||
if(null !== $customer = $session->getCustomerUser()) {
|
if (null !== $customer = $session->getCustomerUser()) {
|
||||||
$cart->setCustomer($customer);
|
$cart->setCustomer($customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,13 +100,12 @@ trait CartTrait {
|
|||||||
return $cart;
|
return $cart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* try to duplicate existing Cart. Customer is here to determine if this cart belong to him.
|
* try to duplicate existing Cart. Customer is here to determine if this cart belong to him.
|
||||||
*
|
*
|
||||||
* @param \Thelia\Model\Cart $cart
|
* @param \Thelia\Model\Cart $cart
|
||||||
* @param \Thelia\Core\HttpFoundation\Session\Session $session
|
* @param \Thelia\Core\HttpFoundation\Session\Session $session
|
||||||
* @param \Thelia\Model\Customer $customer
|
* @param \Thelia\Model\Customer $customer
|
||||||
* @return \Thelia\Model\Cart
|
* @return \Thelia\Model\Cart
|
||||||
*/
|
*/
|
||||||
protected function duplicateCart(CartModel $cart, Session $session, Customer $customer = null)
|
protected function duplicateCart(CartModel $cart, Session $session, Customer $customer = null)
|
||||||
@@ -135,4 +131,4 @@ trait CartTrait {
|
|||||||
return $id;
|
return $id;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,12 +22,8 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Command;
|
namespace Thelia\Command;
|
||||||
|
|
||||||
use Propel\Runtime\Propel;
|
abstract class BaseModuleGenerate extends ContainerAwareCommand
|
||||||
use Symfony\Component\Console\Application;
|
{
|
||||||
|
|
||||||
|
|
||||||
abstract class BaseModuleGenerate extends ContainerAwareCommand {
|
|
||||||
|
|
||||||
protected $module;
|
protected $module;
|
||||||
protected $moduleDirectory;
|
protected $moduleDirectory;
|
||||||
|
|
||||||
@@ -53,6 +49,7 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand {
|
|||||||
if (in_array(strtolower($name), $this->reservedKeyWords)) {
|
if (in_array(strtolower($name), $this->reservedKeyWords)) {
|
||||||
throw new \RuntimeException(sprintf("%s module name is a reserved keyword", $name));
|
throw new \RuntimeException(sprintf("%s module name is a reserved keyword", $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ucfirst($name);
|
return ucfirst($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
namespace Thelia\Command;
|
namespace Thelia\Command;
|
||||||
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
@@ -56,9 +55,9 @@ class CacheClear extends ContainerAwareCommand
|
|||||||
$fs->remove($cacheDir);
|
$fs->remove($cacheDir);
|
||||||
|
|
||||||
$output->writeln("<info>cache cleared successfully</info>");
|
$output->writeln("<info>cache cleared successfully</info>");
|
||||||
} catch(IOException $e) {
|
} catch (IOException $e) {
|
||||||
$output->writeln(sprintf("error during clearing cache : %s", $e->getMessage()));
|
$output->writeln(sprintf("error during clearing cache : %s", $e->getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
|||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class ContainerAwareCommand extends Command implements ContainerAwareInterface {
|
class ContainerAwareCommand extends Command implements ContainerAwareInterface
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var ContainerInterface
|
* @var ContainerInterface
|
||||||
*/
|
*/
|
||||||
@@ -57,4 +58,4 @@ class ContainerAwareCommand extends Command implements ContainerAwareInterface {
|
|||||||
{
|
{
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Thelia\Command\ContainerAwareCommand;
|
use Thelia\Command\ContainerAwareCommand;
|
||||||
|
|
||||||
|
|
||||||
class Install extends ContainerAwareCommand
|
class Install extends ContainerAwareCommand
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -80,7 +79,6 @@ class Install extends ContainerAwareCommand
|
|||||||
|
|
||||||
$this->checkPermission($output);
|
$this->checkPermission($output);
|
||||||
|
|
||||||
|
|
||||||
$connectionInfo = array(
|
$connectionInfo = array(
|
||||||
"host" => $input->getOption("db_host"),
|
"host" => $input->getOption("db_host"),
|
||||||
"dbName" => $input->getOption("db_name"),
|
"dbName" => $input->getOption("db_name"),
|
||||||
@@ -88,9 +86,7 @@ class Install extends ContainerAwareCommand
|
|||||||
"password" => $input->getOption("db_password")
|
"password" => $input->getOption("db_password")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
while (false === $connection = $this->tryConnection($connectionInfo, $output)) {
|
||||||
|
|
||||||
while(false === $connection = $this->tryConnection($connectionInfo, $output)) {
|
|
||||||
$connectionInfo = $this->getConnectionInfo($input, $output);
|
$connectionInfo = $this->getConnectionInfo($input, $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,8 +160,6 @@ class Install extends ContainerAwareCommand
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -180,7 +174,6 @@ class Install extends ContainerAwareCommand
|
|||||||
$sampleConfigFile = THELIA_ROOT . "/local/config/database.yml.sample";
|
$sampleConfigFile = THELIA_ROOT . "/local/config/database.yml.sample";
|
||||||
$configFile = THELIA_ROOT . "/local/config/database.yml";
|
$configFile = THELIA_ROOT . "/local/config/database.yml";
|
||||||
|
|
||||||
|
|
||||||
$fs->copy($sampleConfigFile, $configFile, true);
|
$fs->copy($sampleConfigFile, $configFile, true);
|
||||||
|
|
||||||
$configContent = file_get_contents($configFile);
|
$configContent = file_get_contents($configFile);
|
||||||
@@ -200,7 +193,6 @@ class Install extends ContainerAwareCommand
|
|||||||
|
|
||||||
$fs->remove($this->getContainer()->getParameter("kernel.cache_dir"));
|
$fs->remove($this->getContainer()->getParameter("kernel.cache_dir"));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -237,7 +229,7 @@ class Install extends ContainerAwareCommand
|
|||||||
|
|
||||||
$tab = explode(";", $sql);
|
$tab = explode(";", $sql);
|
||||||
|
|
||||||
for($i=0; $i<count($tab); $i++){
|
for ($i=0; $i<count($tab); $i++) {
|
||||||
$queryTemp = str_replace("-CODE-", ";',", $tab[$i]);
|
$queryTemp = str_replace("-CODE-", ";',", $tab[$i]);
|
||||||
$queryTemp = str_replace("|", ";", $queryTemp);
|
$queryTemp = str_replace("|", ";", $queryTemp);
|
||||||
$query[] = $queryTemp;
|
$query[] = $queryTemp;
|
||||||
@@ -266,7 +258,7 @@ class Install extends ContainerAwareCommand
|
|||||||
* test database access
|
* test database access
|
||||||
*
|
*
|
||||||
* @param $connectionInfo
|
* @param $connectionInfo
|
||||||
* @param OutputInterface $output
|
* @param OutputInterface $output
|
||||||
* @return bool|\PDO
|
* @return bool|\PDO
|
||||||
*/
|
*/
|
||||||
protected function tryConnection($connectionInfo, OutputInterface $output)
|
protected function tryConnection($connectionInfo, OutputInterface $output)
|
||||||
@@ -288,19 +280,18 @@ class Install extends ContainerAwareCommand
|
|||||||
$output->writeln(array(
|
$output->writeln(array(
|
||||||
"<error>Wrong connection information</error>"
|
"<error>Wrong connection information</error>"
|
||||||
));
|
));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $connection;
|
return $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ask to user all needed information
|
* Ask to user all needed information
|
||||||
*
|
*
|
||||||
* @param InputInterface $input
|
* @param InputInterface $input
|
||||||
* @param OutputInterface $output
|
* @param OutputInterface $output
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getConnectionInfo(InputInterface $input, OutputInterface $output)
|
protected function getConnectionInfo(InputInterface $input, OutputInterface $output)
|
||||||
@@ -363,4 +354,4 @@ class Install extends ContainerAwareCommand
|
|||||||
return sprintf("<info>%s</info>", $text);
|
return sprintf("<info>%s</info>", $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,16 +22,13 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Command;
|
namespace Thelia\Command;
|
||||||
|
|
||||||
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
|
||||||
class ModuleGenerateCommand extends BaseModuleGenerate {
|
class ModuleGenerateCommand extends BaseModuleGenerate
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
@@ -53,7 +50,7 @@ class ModuleGenerateCommand extends BaseModuleGenerate {
|
|||||||
|
|
||||||
$this->createDirectories();
|
$this->createDirectories();
|
||||||
$this->createFiles();
|
$this->createFiles();
|
||||||
if(method_exists($this, "renderBlock")) {
|
if (method_exists($this, "renderBlock")) {
|
||||||
//impossible to change output class in CommandTester...
|
//impossible to change output class in CommandTester...
|
||||||
$output->renderBlock(array(
|
$output->renderBlock(array(
|
||||||
'',
|
'',
|
||||||
@@ -99,6 +96,4 @@ class ModuleGenerateCommand extends BaseModuleGenerate {
|
|||||||
file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . "Config". DIRECTORY_SEPARATOR . "schema.xml", $schemaContent);
|
file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . "Config". DIRECTORY_SEPARATOR . "schema.xml", $schemaContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -23,18 +23,16 @@
|
|||||||
|
|
||||||
namespace Thelia\Command;
|
namespace Thelia\Command;
|
||||||
|
|
||||||
|
|
||||||
use Propel\Generator\Command\ModelBuildCommand;
|
use Propel\Generator\Command\ModelBuildCommand;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Output\StreamOutput;
|
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
|
||||||
class ModuleGenerateModelCommand extends BaseModuleGenerate {
|
class ModuleGenerateModelCommand extends BaseModuleGenerate
|
||||||
|
{
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
@@ -124,7 +122,6 @@ class ModuleGenerateModelCommand extends BaseModuleGenerate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,17 +23,15 @@
|
|||||||
|
|
||||||
namespace Thelia\Command;
|
namespace Thelia\Command;
|
||||||
|
|
||||||
|
|
||||||
use Propel\Generator\Command\SqlBuildCommand;
|
use Propel\Generator\Command\SqlBuildCommand;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Output\StreamOutput;
|
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
|
||||||
class ModuleGenerateSqlCommand extends BaseModuleGenerate {
|
class ModuleGenerateSqlCommand extends BaseModuleGenerate
|
||||||
|
{
|
||||||
public function configure()
|
public function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
@@ -82,4 +80,4 @@ class ModuleGenerateSqlCommand extends BaseModuleGenerate {
|
|||||||
), 'bg=green;fg=black');
|
), 'bg=green;fg=black');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,10 @@
|
|||||||
|
|
||||||
namespace Thelia\Command\Output;
|
namespace Thelia\Command\Output;
|
||||||
|
|
||||||
|
|
||||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
|
|
||||||
class TheliaConsoleOutput extends ConsoleOutput{
|
class TheliaConsoleOutput extends ConsoleOutput
|
||||||
|
{
|
||||||
public function renderBlock(array $messages, $style = "info")
|
public function renderBlock(array $messages, $style = "info")
|
||||||
{
|
{
|
||||||
$strlen = function ($string) {
|
$strlen = function ($string) {
|
||||||
@@ -53,4 +52,4 @@ class TheliaConsoleOutput extends ConsoleOutput{
|
|||||||
$this->writeln($output);
|
$this->writeln($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,12 +21,11 @@
|
|||||||
/* */
|
/* */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
namespace %%NAMESPACE%%;
|
namespace %%NAMESPACE%%;
|
||||||
|
|
||||||
use Thelia\Module\BaseModule;
|
use Thelia\Module\BaseModule;
|
||||||
|
|
||||||
class %%CLASSNAME%% extends BaseModule
|
class Class extends BaseModule
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class
|
* YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class
|
||||||
|
|||||||
@@ -69,4 +69,4 @@ class DatabaseConfiguration implements ConfigurationInterface
|
|||||||
|
|
||||||
return $treeBuilder;
|
return $treeBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,8 @@ namespace Thelia\Config;
|
|||||||
use Symfony\Component\Config\Definition\Processor;
|
use Symfony\Component\Config\Definition\Processor;
|
||||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||||
|
|
||||||
|
class DefinePropel
|
||||||
class DefinePropel {
|
{
|
||||||
|
|
||||||
private $processorConfig;
|
private $processorConfig;
|
||||||
|
|
||||||
public function __construct(ConfigurationInterface $configuration, array $propelConf)
|
public function __construct(ConfigurationInterface $configuration, array $propelConf)
|
||||||
@@ -40,6 +39,7 @@ class DefinePropel {
|
|||||||
public function getConfig()
|
public function getConfig()
|
||||||
{
|
{
|
||||||
$connection = $this->processorConfig["connection"];
|
$connection = $this->processorConfig["connection"];
|
||||||
|
|
||||||
return $conf = array(
|
return $conf = array(
|
||||||
"dsn" => $connection["dsn"],
|
"dsn" => $connection["dsn"],
|
||||||
"user" => $connection["user"],
|
"user" => $connection["user"],
|
||||||
@@ -47,4 +47,4 @@ class DefinePropel {
|
|||||||
"classname" => $connection["classname"]
|
"classname" => $connection["classname"]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,4 +29,4 @@
|
|||||||
|
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
</config>
|
</config>
|
||||||
|
|||||||
@@ -72,4 +72,4 @@
|
|||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
</config>
|
</config>
|
||||||
|
|||||||
@@ -41,4 +41,4 @@
|
|||||||
<default key="_controller">Thelia\Controller\Admin\AdminController::processTemplateAction</default>
|
<default key="_controller">Thelia\Controller\Admin\AdminController::processTemplateAction</default>
|
||||||
<requirement key="template">.*</requirement>
|
<requirement key="template">.*</requirement>
|
||||||
</route>
|
</route>
|
||||||
</routes>
|
</routes>
|
||||||
|
|||||||
@@ -26,4 +26,4 @@
|
|||||||
<route id="cart.change.process" path="/cart/delete" methods="post">
|
<route id="cart.change.process" path="/cart/delete" methods="post">
|
||||||
<default key="_controller">Thelia\Controller\Front\CartController::deleteArticle</default>
|
<default key="_controller">Thelia\Controller\Front\CartController::deleteArticle</default>
|
||||||
</route>
|
</route>
|
||||||
</routes>
|
</routes>
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class BaseController extends ContainerAware
|
|||||||
/**
|
/**
|
||||||
* Create an action event
|
* Create an action event
|
||||||
*
|
*
|
||||||
* @param string $action
|
* @param string $action
|
||||||
* @return EventDispatcher
|
* @return EventDispatcher
|
||||||
*/
|
*/
|
||||||
protected function dispatchEvent($action)
|
protected function dispatchEvent($action)
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Controller\Front;
|
namespace Thelia\Controller\Front;
|
||||||
|
|
||||||
use Thelia\Controller\NullControllerInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
namespace Thelia\Core;
|
namespace Thelia\Core;
|
||||||
|
|
||||||
|
|
||||||
class Context
|
class Context
|
||||||
{
|
{
|
||||||
const CONTEXT_FRONT_OFFICE = 'front';
|
const CONTEXT_FRONT_OFFICE = 'front';
|
||||||
@@ -43,8 +42,7 @@ class Context
|
|||||||
|
|
||||||
public function setContext($context)
|
public function setContext($context)
|
||||||
{
|
{
|
||||||
if($this->isValidContext($context))
|
if ($this->isValidContext($context)) {
|
||||||
{
|
|
||||||
$this->currentContext = $context;
|
$this->currentContext = $context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,4 +51,4 @@ class Context
|
|||||||
{
|
{
|
||||||
return $this->currentContext;
|
return $this->currentContext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,8 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Core\DependencyInjection\Compiler;
|
namespace Thelia\Core\DependencyInjection\Compiler;
|
||||||
|
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
|
||||||
@@ -43,7 +41,7 @@ class RegisterRouterPass implements CompilerPassInterface
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$chainRouter = $container->getDefinition("router.chainRequest");
|
$chainRouter = $container->getDefinition("router.chainRequest");
|
||||||
} catch(InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,8 +53,6 @@ class RegisterRouterPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$chainRouter->addMethodCall("add", array(new Reference($id), $priority));
|
$chainRouter->addMethodCall("add", array(new Reference($id), $priority));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ namespace Thelia\Core\Event;
|
|||||||
use Symfony\Component\EventDispatcher\Event;
|
use Symfony\Component\EventDispatcher\Event;
|
||||||
use Thelia\Core\HttpFoundation\Request;
|
use Thelia\Core\HttpFoundation\Request;
|
||||||
use Thelia\Form\BaseForm;
|
use Thelia\Form\BaseForm;
|
||||||
use Thelia\Core\Security\SecurityContext;
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Class thrown on Thelia.action event
|
* Class thrown on Thelia.action event
|
||||||
@@ -43,7 +42,6 @@ abstract class ActionEvent extends Event
|
|||||||
*/
|
*/
|
||||||
protected $request;
|
protected $request;
|
||||||
|
|
||||||
|
|
||||||
protected $errorForm = null;
|
protected $errorForm = null;
|
||||||
|
|
||||||
protected $parameters = array();
|
protected $parameters = array();
|
||||||
@@ -58,7 +56,6 @@ abstract class ActionEvent extends Event
|
|||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function __set($name, $value)
|
public function __set($name, $value)
|
||||||
{
|
{
|
||||||
$this->parameters[$name] = $value;
|
$this->parameters[$name] = $value;
|
||||||
@@ -82,17 +79,20 @@ abstract class ActionEvent extends Event
|
|||||||
return $this->request;
|
return $this->request;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setErrorForm(BaseForm $form) {
|
public function setErrorForm(BaseForm $form)
|
||||||
$this->errorForm = $form;
|
{
|
||||||
|
$this->errorForm = $form;
|
||||||
|
|
||||||
if ($form != null) $this->stopPropagation();
|
if ($form != null) $this->stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getErrorForm() {
|
public function getErrorForm()
|
||||||
return $this->errorForm;
|
{
|
||||||
|
return $this->errorForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasErrorForm() {
|
public function hasErrorForm()
|
||||||
return $this->errorForm != null ? true : false;
|
{
|
||||||
|
return $this->errorForm != null ? true : false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ namespace Thelia\Core\Event;
|
|||||||
use Thelia\Core\HttpFoundation\Request;
|
use Thelia\Core\HttpFoundation\Request;
|
||||||
use Thelia\Model\Cart;
|
use Thelia\Model\Cart;
|
||||||
|
|
||||||
class CartEvent extends ActionEvent {
|
class CartEvent extends ActionEvent
|
||||||
|
{
|
||||||
protected $cart;
|
protected $cart;
|
||||||
|
|
||||||
public function __construct(Request $request, Cart $cart)
|
public function __construct(Request $request, Cart $cart)
|
||||||
@@ -40,4 +40,4 @@ class CartEvent extends ActionEvent {
|
|||||||
{
|
{
|
||||||
return $this->cart;
|
return $this->cart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,10 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\Event;
|
namespace Thelia\Core\Event;
|
||||||
|
|
||||||
|
|
||||||
use Thelia\Model\CartItem;
|
use Thelia\Model\CartItem;
|
||||||
|
|
||||||
class CartItemEvent extends InternalEvent {
|
class CartItemEvent extends InternalEvent
|
||||||
|
{
|
||||||
protected $cartItem;
|
protected $cartItem;
|
||||||
|
|
||||||
public function __construct(CartItem $cartItem)
|
public function __construct(CartItem $cartItem)
|
||||||
@@ -39,4 +38,4 @@ class CartItemEvent extends InternalEvent {
|
|||||||
{
|
{
|
||||||
return $this->cartItem;
|
return $this->cartItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,15 +23,14 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\Event;
|
namespace Thelia\Core\Event;
|
||||||
|
|
||||||
|
|
||||||
use Thelia\Model\Category;
|
use Thelia\Model\Category;
|
||||||
|
|
||||||
class CategoryEvent extends InternalEvent {
|
class CategoryEvent extends InternalEvent
|
||||||
|
{
|
||||||
public $category;
|
public $category;
|
||||||
|
|
||||||
public function __construct(Category $category)
|
public function __construct(Category $category)
|
||||||
{
|
{
|
||||||
$this->category = $category;
|
$this->category = $category;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,14 +21,12 @@
|
|||||||
/* */
|
/* */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
namespace Thelia\Core\Event\Internal;
|
namespace Thelia\Core\Event\Internal;
|
||||||
|
|
||||||
|
|
||||||
use Thelia\Model\Cart;
|
use Thelia\Model\Cart;
|
||||||
|
|
||||||
class CartEvent extends InternalEvent {
|
class CartEvent extends InternalEvent
|
||||||
|
{
|
||||||
public $cart;
|
public $cart;
|
||||||
|
|
||||||
public function __construct(Cart $cart)
|
public function __construct(Cart $cart)
|
||||||
@@ -36,6 +34,4 @@ class CartEvent extends InternalEvent {
|
|||||||
$this->cart = $cart;
|
$this->cart = $cart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -23,11 +23,10 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\Event\Internal;
|
namespace Thelia\Core\Event\Internal;
|
||||||
|
|
||||||
|
|
||||||
use Thelia\Model\Customer;
|
use Thelia\Model\Customer;
|
||||||
|
|
||||||
class CustomerEvent extends InternalEvent {
|
class CustomerEvent extends InternalEvent
|
||||||
|
{
|
||||||
public $customer;
|
public $customer;
|
||||||
|
|
||||||
public function __construct(Customer $customer)
|
public function __construct(Customer $customer)
|
||||||
@@ -35,4 +34,4 @@ class CustomerEvent extends InternalEvent {
|
|||||||
$this->customer = $customer;
|
$this->customer = $customer;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\Event\Internal;
|
namespace Thelia\Core\Event\Internal;
|
||||||
|
|
||||||
|
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
use Symfony\Component\EventDispatcher\Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,6 +31,6 @@ use Symfony\Component\EventDispatcher\Event;
|
|||||||
* Class InternalEvent
|
* Class InternalEvent
|
||||||
* @package Thelia\Core\Event
|
* @package Thelia\Core\Event
|
||||||
*/
|
*/
|
||||||
abstract class InternalEvent extends Event {
|
abstract class InternalEvent extends Event
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,8 +65,6 @@ final class TheliaEvents
|
|||||||
*/
|
*/
|
||||||
const ADMIN_LOGIN = "action.admin_login";
|
const ADMIN_LOGIN = "action.admin_login";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sent once the customer creation form has been successfully validated, and before customer insertion in the database.
|
* Sent once the customer creation form has been successfully validated, and before customer insertion in the database.
|
||||||
*/
|
*/
|
||||||
@@ -86,8 +84,6 @@ final class TheliaEvents
|
|||||||
*/
|
*/
|
||||||
const AFTER_CHANGECUSTOMER = "action.after_changecustomer";
|
const AFTER_CHANGECUSTOMER = "action.after_changecustomer";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sent once the category creation form has been successfully validated, and before category insertion in the database.
|
* Sent once the category creation form has been successfully validated, and before category insertion in the database.
|
||||||
*/
|
*/
|
||||||
@@ -112,7 +108,6 @@ final class TheliaEvents
|
|||||||
*/
|
*/
|
||||||
const AFTER_CHANGECATEGORY = "action.after_changecategory";
|
const AFTER_CHANGECATEGORY = "action.after_changecategory";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sent when a new existing cat id duplicated. This append when current customer is different from current cart
|
* sent when a new existing cat id duplicated. This append when current customer is different from current cart
|
||||||
*/
|
*/
|
||||||
@@ -139,4 +134,4 @@ final class TheliaEvents
|
|||||||
const CART_CHANGEITEM = "action.changeArticle";
|
const CART_CHANGEITEM = "action.changeArticle";
|
||||||
|
|
||||||
const CART_DELETEITEM = "action.deleteArticle";
|
const CART_DELETEITEM = "action.deleteArticle";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,14 +39,15 @@ use Thelia\Core\Template\ParserContext;
|
|||||||
*/
|
*/
|
||||||
class ControllerListener implements EventSubscriberInterface
|
class ControllerListener implements EventSubscriberInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var ParserContext the parser context
|
* @var ParserContext the parser context
|
||||||
*/
|
*/
|
||||||
protected $parserContext;
|
protected $parserContext;
|
||||||
|
|
||||||
public function __construct(ParserContext $parserContext) {
|
public function __construct(ParserContext $parserContext)
|
||||||
$this->parserContext = $parserContext;
|
{
|
||||||
}
|
$this->parserContext = $parserContext;
|
||||||
|
}
|
||||||
|
|
||||||
public function onKernelController(FilterControllerEvent $event)
|
public function onKernelController(FilterControllerEvent $event)
|
||||||
{
|
{
|
||||||
@@ -61,7 +62,7 @@ class ControllerListener implements EventSubscriberInterface
|
|||||||
|
|
||||||
// Process form errors
|
// Process form errors
|
||||||
if ($actionEvent->hasErrorForm()) {
|
if ($actionEvent->hasErrorForm()) {
|
||||||
$this->parserContext->setErrorForm($actionEvent->getErrorForm());
|
$this->parserContext->setErrorForm($actionEvent->getErrorForm());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,14 +81,12 @@ class ViewListener implements EventSubscriberInterface
|
|||||||
} else {
|
} else {
|
||||||
$event->setResponse(new Response($content, $parser->getStatus() ?: 200));
|
$event->setResponse(new Response($content, $parser->getStatus() ?: 200));
|
||||||
}
|
}
|
||||||
}
|
} catch (ResourceNotFoundException $e) {
|
||||||
catch (ResourceNotFoundException $e) {
|
|
||||||
$event->setResponse(new Response($e->getMessage(), 404));
|
$event->setResponse(new Response($e->getMessage(), 404));
|
||||||
}
|
} catch (AuthenticationException $ex) {
|
||||||
catch (AuthenticationException $ex) {
|
|
||||||
|
|
||||||
// Redirect to the login template
|
// Redirect to the login template
|
||||||
$event->setResponse(Redirect::exec(URL::viewUrl($ex->getLoginTemplate())));
|
$event->setResponse(Redirect::exec(URL::viewUrl($ex->getLoginTemplate())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
namespace Thelia\Core\HttpFoundation;
|
namespace Thelia\Core\HttpFoundation;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request as BaseRequest;
|
use Symfony\Component\HttpFoundation\Request as BaseRequest;
|
||||||
use Thelia\Core\Context;
|
|
||||||
|
|
||||||
class Request extends BaseRequest
|
class Request extends BaseRequest
|
||||||
{
|
{
|
||||||
@@ -46,6 +45,7 @@ class Request extends BaseRequest
|
|||||||
if ('' == $this->getQueryString()) {
|
if ('' == $this->getQueryString()) {
|
||||||
$additionalQs = '?'. ltrim($additionalQs, '&');
|
$additionalQs = '?'. ltrim($additionalQs, '&');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $uri . $additionalQs;
|
return $uri . $additionalQs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ class Session extends BaseSession
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param \Thelia\Model\Cart $cart
|
* @param \Thelia\Model\Cart $cart
|
||||||
* @throws \Thelia\Exception\InvalidCartException
|
* @throws \Thelia\Exception\InvalidCartException
|
||||||
*/
|
*/
|
||||||
protected function verifyValidCart(Cart $cart)
|
protected function verifyValidCart(Cart $cart)
|
||||||
@@ -128,7 +128,7 @@ class Session extends BaseSession
|
|||||||
$customer = $this->getCustomerUser();
|
$customer = $this->getCustomerUser();
|
||||||
if ($customer && $cart->getCustomerId() != $customer->getId()) {
|
if ($customer && $cart->getCustomerId() != $customer->getId()) {
|
||||||
throw new InvalidCartException("customer in session and customer_id in cart are not the same");
|
throw new InvalidCartException("customer in session and customer_id in cart are not the same");
|
||||||
} else if($customer === null && $cart->getCustomerId() !== null) {
|
} elseif ($customer === null && $cart->getCustomerId() !== null) {
|
||||||
throw new InvalidCartException("Customer exists in cart and not in session");
|
throw new InvalidCartException("Customer exists in cart and not in session");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,13 +31,14 @@ use Thelia\Core\Security\UserProvider\AdminUserProvider;
|
|||||||
use Thelia\Core\Security\Authentication\UsernamePasswordFormAuthenticator;
|
use Thelia\Core\Security\Authentication\UsernamePasswordFormAuthenticator;
|
||||||
use Thelia\Form\AdminLogin;
|
use Thelia\Form\AdminLogin;
|
||||||
|
|
||||||
class AdminUsernamePasswordFormAuthenticator extends UsernamePasswordFormAuthenticator {
|
class AdminUsernamePasswordFormAuthenticator extends UsernamePasswordFormAuthenticator
|
||||||
|
{
|
||||||
public function __construct(Request $request, AdminLogin $loginForm) {
|
public function __construct(Request $request, AdminLogin $loginForm)
|
||||||
parent::__construct(
|
{
|
||||||
$request,
|
parent::__construct(
|
||||||
$loginForm,
|
$request,
|
||||||
new AdminUserProvider()
|
$loginForm,
|
||||||
);
|
new AdminUserProvider()
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,10 +23,10 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\Security\Authentication;
|
namespace Thelia\Core\Security\Authentication;
|
||||||
|
|
||||||
interface AuthenticatorInterface {
|
interface AuthenticatorInterface
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Returns a UserInterface instance, authentified using the authenticator specific method
|
* Returns a UserInterface instance, authentified using the authenticator specific method
|
||||||
*/
|
*/
|
||||||
public function getAuthentifiedUser();
|
public function getAuthentifiedUser();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,16 +29,17 @@ use Thelia\Core\Security\Authentication\UsernamePasswordFormAuthenticator;
|
|||||||
use Thelia\Form\CustomerLogin;
|
use Thelia\Form\CustomerLogin;
|
||||||
use Thelia\Core\Security\UserProvider\CustomerUserProvider;
|
use Thelia\Core\Security\UserProvider\CustomerUserProvider;
|
||||||
|
|
||||||
class CustomerUsernamePasswordFormAuthenticator extends UsernamePasswordFormAuthenticator {
|
class CustomerUsernamePasswordFormAuthenticator extends UsernamePasswordFormAuthenticator
|
||||||
|
{
|
||||||
public function __construct(Request $request, CustomerLogin $loginForm) {
|
public function __construct(Request $request, CustomerLogin $loginForm)
|
||||||
parent::__construct(
|
{
|
||||||
$request,
|
parent::__construct(
|
||||||
$loginForm,
|
$request,
|
||||||
new CustomerUserProvider(),
|
$loginForm,
|
||||||
array(
|
new CustomerUserProvider(),
|
||||||
'username_field_name' => 'email'
|
array(
|
||||||
)
|
'username_field_name' => 'email'
|
||||||
);
|
)
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,64 +32,65 @@ use Thelia\Core\Security\Exception\UsernameNotFoundException;
|
|||||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||||
use Thelia\Form\BaseForm;
|
use Thelia\Form\BaseForm;
|
||||||
|
|
||||||
class UsernamePasswordFormAuthenticator implements AuthenticatorInterface {
|
class UsernamePasswordFormAuthenticator implements AuthenticatorInterface
|
||||||
|
{
|
||||||
|
protected $request;
|
||||||
|
protected $loginForm;
|
||||||
|
protected $userProvider;
|
||||||
|
protected $options;
|
||||||
|
|
||||||
protected $request;
|
protected $baseLoginForm;
|
||||||
protected $loginForm;
|
|
||||||
protected $userProvider;
|
|
||||||
protected $options;
|
|
||||||
|
|
||||||
protected $baseLoginForm;
|
public function __construct(Request $request, BaseForm $loginForm, UserProviderInterface $userProvider, array $options = array())
|
||||||
|
{
|
||||||
|
$this->request = $request;
|
||||||
|
$this->baseLoginForm = $loginForm;
|
||||||
|
$this->loginForm = $this->baseLoginForm->getForm();
|
||||||
|
$this->userProvider = $userProvider;
|
||||||
|
|
||||||
public function __construct(Request $request, BaseForm $loginForm, UserProviderInterface $userProvider, array $options = array()) {
|
$defaults = array(
|
||||||
$this->request = $request;
|
'required_method' => 'POST',
|
||||||
$this->baseLoginForm = $loginForm;
|
'username_field_name' => 'username',
|
||||||
$this->loginForm = $this->baseLoginForm->getForm();
|
'password_field_name' => 'password'
|
||||||
$this->userProvider = $userProvider;
|
);
|
||||||
|
|
||||||
$defaults = array(
|
$this->options = array_merge($defaults, $options);
|
||||||
'required_method' => 'POST',
|
|
||||||
'username_field_name' => 'username',
|
|
||||||
'password_field_name' => 'password'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->options = array_merge($defaults, $options);
|
$this->loginForm->bind($this->request);
|
||||||
|
}
|
||||||
|
|
||||||
$this->loginForm->bind($this->request);
|
/**
|
||||||
}
|
* @return string the username value
|
||||||
|
*/
|
||||||
|
public function getUsername()
|
||||||
|
{
|
||||||
|
return $this->loginForm->get($this->options['username_field_name'])->getData();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string the username value
|
* @see \Thelia\Core\Security\Authentication\AuthenticatorInterface::getAuthentifiedUser()
|
||||||
*/
|
*/
|
||||||
public function getUsername() {
|
public function getAuthentifiedUser()
|
||||||
return $this->loginForm->get($this->options['username_field_name'])->getData();
|
{
|
||||||
}
|
if ($this->request->isMethod($this->options['required_method'])) {
|
||||||
|
|
||||||
/**
|
if (! $this->loginForm->isValid()) throw new ValidatorException("Form is not valid.");
|
||||||
* @see \Thelia\Core\Security\Authentication\AuthenticatorInterface::getAuthentifiedUser()
|
|
||||||
*/
|
|
||||||
public function getAuthentifiedUser() {
|
|
||||||
|
|
||||||
if ($this->request->isMethod($this->options['required_method'])) {
|
// Retreive user
|
||||||
|
$username = $this->getUsername();
|
||||||
|
$password = $this->loginForm->get($this->options['password_field_name'])->getData();
|
||||||
|
|
||||||
if (! $this->loginForm->isValid()) throw new ValidatorException("Form is not valid.");
|
$user = $this->userProvider->getUser($username);
|
||||||
|
|
||||||
// Retreive user
|
if ($user === null) throw new UsernameNotFoundException(sprintf("Username '%s' was not found.", $username));
|
||||||
$username = $this->getUsername();
|
|
||||||
$password = $this->loginForm->get($this->options['password_field_name'])->getData();
|
|
||||||
|
|
||||||
$user = $this->userProvider->getUser($username);
|
// Check user password
|
||||||
|
$authOk = $user->checkPassword($password) === true;
|
||||||
|
|
||||||
if ($user === null) throw new UsernameNotFoundException(sprintf("Username '%s' was not found.", $username));
|
if ($authOk !== true) throw new WrongPasswordException(sprintf("Wrong password for user '%s'.", $username));
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
// Check user password
|
throw new \RuntimeException("Invalid method.");
|
||||||
$authOk = $user->checkPassword($password) === true;
|
}
|
||||||
|
}
|
||||||
if ($authOk !== true) throw new WrongPasswordException(sprintf("Wrong password for user '%s'.", $username));
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \RuntimeException("Invalid method.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -25,24 +25,26 @@ namespace Thelia\Core\Security\Exception;
|
|||||||
|
|
||||||
class AuthenticationException extends \Exception
|
class AuthenticationException extends \Exception
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string The login template name
|
* @var string The login template name
|
||||||
*/
|
*/
|
||||||
protected $loginTemplate = "login";
|
protected $loginTemplate = "login";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string the login template name
|
* @return string the login template name
|
||||||
*/
|
*/
|
||||||
public function getLoginTemplate() {
|
public function getLoginTemplate()
|
||||||
return $this->loginTemplate;
|
{
|
||||||
}
|
return $this->loginTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the login template name
|
* Set the login template name
|
||||||
*
|
*
|
||||||
* @param string $loginPath the login template name
|
* @param string $loginPath the login template name
|
||||||
*/
|
*/
|
||||||
public function setLoginTemplate($loginTemplate) {
|
public function setLoginTemplate($loginTemplate)
|
||||||
$this->loginTemplate = $loginTemplate;
|
{
|
||||||
}
|
$this->loginTemplate = $loginTemplate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ class Role implements RoleInterface
|
|||||||
return $this->role;
|
return $this->role;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString() {
|
public function __toString()
|
||||||
return $this->role;
|
{
|
||||||
|
return $this->role;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,4 +32,4 @@ interface RoleInterface
|
|||||||
* @return string|null A string representation of the role, or null
|
* @return string|null A string representation of the role, or null
|
||||||
*/
|
*/
|
||||||
public function getRole();
|
public function getRole();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,6 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\Security;
|
namespace Thelia\Core\Security;
|
||||||
|
|
||||||
use Thelia\Core\Security\Authentication\AuthenticationProviderInterface;
|
|
||||||
use Thelia\Core\Security\Exception\AuthenticationTokenNotFoundException;
|
|
||||||
use Thelia\Core\Security\Token\TokenInterface;
|
|
||||||
use Thelia\Core\Security\User\UserInterface;
|
use Thelia\Core\Security\User\UserInterface;
|
||||||
use Thelia\Core\HttpFoundation\Request;
|
use Thelia\Core\HttpFoundation\Request;
|
||||||
|
|
||||||
@@ -34,73 +31,77 @@ use Thelia\Core\HttpFoundation\Request;
|
|||||||
*
|
*
|
||||||
* @author Franck Allimant <franck@cqfdev.fr>
|
* @author Franck Allimant <franck@cqfdev.fr>
|
||||||
*/
|
*/
|
||||||
class SecurityContext {
|
class SecurityContext
|
||||||
|
{
|
||||||
|
const CONTEXT_FRONT_OFFICE = 'front';
|
||||||
|
const CONTEXT_BACK_OFFICE = 'admin';
|
||||||
|
|
||||||
const CONTEXT_FRONT_OFFICE = 'front';
|
private $request;
|
||||||
const CONTEXT_BACK_OFFICE = 'admin';
|
private $context;
|
||||||
|
|
||||||
private $request;
|
public function __construct(Request $request)
|
||||||
private $context;
|
{
|
||||||
|
$this->request = $request;
|
||||||
|
|
||||||
public function __construct(Request $request) {
|
$this->context = null;
|
||||||
|
}
|
||||||
|
|
||||||
$this->request = $request;
|
public function setContext($context)
|
||||||
|
{
|
||||||
|
if ($context !== self::CONTEXT_FRONT_OFFICE && $context !== self::CONTEXT_BACK_OFFICE) {
|
||||||
|
throw new \InvalidArgumentException(sprintf("Invalid or empty context identifier '%s'", $context));
|
||||||
|
}
|
||||||
|
|
||||||
$this->context = null;
|
$this->context = $context;
|
||||||
}
|
|
||||||
|
|
||||||
public function setContext($context) {
|
return $this;
|
||||||
if ($context !== self::CONTEXT_FRONT_OFFICE && $context !== self::CONTEXT_BACK_OFFICE) {
|
}
|
||||||
throw new \InvalidArgumentException(sprintf("Invalid or empty context identifier '%s'", $context));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->context = $context;
|
public function getContext($exception_if_context_undefined = false)
|
||||||
|
{
|
||||||
|
if (null === $this->context && $exception_if_context_undefined === true)
|
||||||
|
throw new \LogicException("No context defined. Please use setContext() first.");
|
||||||
|
|
||||||
return $this;
|
return $this->context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContext($exception_if_context_undefined = false) {
|
private function getSession()
|
||||||
if (null === $this->context && $exception_if_context_undefined === true)
|
{
|
||||||
throw new \LogicException("No context defined. Please use setContext() first.");
|
$session = $this->request->getSession();
|
||||||
|
|
||||||
return $this->context;
|
if ($session === null)
|
||||||
}
|
throw new \LogicException("No session found.");
|
||||||
|
|
||||||
private function getSession() {
|
return $session;
|
||||||
$session = $this->request->getSession();
|
}
|
||||||
|
|
||||||
if ($session === null)
|
|
||||||
throw new \LogicException("No session found.");
|
|
||||||
|
|
||||||
return $session;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the currently authenticated user in the current context, or null if none is defined
|
* Gets the currently authenticated user in the current context, or null if none is defined
|
||||||
*
|
*
|
||||||
* @return UserInterface|null A UserInterface instance or null if no user is available
|
* @return UserInterface|null A UserInterface instance or null if no user is available
|
||||||
*/
|
*/
|
||||||
public function getUser() {
|
public function getUser()
|
||||||
$context = $this->getContext(true);
|
{
|
||||||
|
$context = $this->getContext(true);
|
||||||
|
|
||||||
if ($context === self::CONTEXT_FRONT_OFFICE)
|
if ($context === self::CONTEXT_FRONT_OFFICE)
|
||||||
$user = $this->getSession()->getCustomerUser();
|
$user = $this->getSession()->getCustomerUser();
|
||||||
else if ($context == self::CONTEXT_BACK_OFFICE)
|
else if ($context == self::CONTEXT_BACK_OFFICE)
|
||||||
$user = $this->getSession()->getAdminUser();
|
$user = $this->getSession()->getAdminUser();
|
||||||
else
|
else
|
||||||
$user = null;
|
$user = null;
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function isAuthenticated()
|
final public function isAuthenticated()
|
||||||
{
|
{
|
||||||
if (null !== $this->getUser()) {
|
if (null !== $this->getUser()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the current user is allowed
|
* Checks if the current user is allowed
|
||||||
@@ -111,51 +112,51 @@ class SecurityContext {
|
|||||||
{
|
{
|
||||||
if ($this->isAuthenticated() === true) {
|
if ($this->isAuthenticated() === true) {
|
||||||
|
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
|
|
||||||
// Check if user's roles matches required roles
|
// Check if user's roles matches required roles
|
||||||
$userRoles = $user->getRoles();
|
$userRoles = $user->getRoles();
|
||||||
|
|
||||||
$roleFound = false;
|
$roleFound = false;
|
||||||
|
|
||||||
foreach($userRoles as $role) {
|
foreach ($userRoles as $role) {
|
||||||
if (in_array($role, $roles)) {
|
if (in_array($role, $roles)) {
|
||||||
$roleFound = true;
|
$roleFound = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($roleFound) {
|
if ($roleFound) {
|
||||||
|
|
||||||
if (empty($permissions)) {
|
if (empty($permissions)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get permissions from profile
|
// Get permissions from profile
|
||||||
// $userPermissions = $user->getPermissions(); FIXME
|
// $userPermissions = $user->getPermissions(); FIXME
|
||||||
|
|
||||||
// TODO: Finalize permissions system !;
|
// TODO: Finalize permissions system !;
|
||||||
|
|
||||||
$userPermissions = array('*'); // FIXME !
|
$userPermissions = array('*'); // FIXME !
|
||||||
|
|
||||||
$permissionsFound = true;
|
$permissionsFound = true;
|
||||||
|
|
||||||
// User have all permissions ?
|
// User have all permissions ?
|
||||||
if (in_array('*', $userPermissions))
|
if (in_array('*', $userPermissions))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Check that user's permissions matches required permissions
|
// Check that user's permissions matches required permissions
|
||||||
foreach($permissions as $permission) {
|
foreach ($permissions as $permission) {
|
||||||
if (! in_array($permission, $userPermissions)) {
|
if (! in_array($permission, $userPermissions)) {
|
||||||
$permissionsFound = false;
|
$permissionsFound = false;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $permissionsFound;
|
return $permissionsFound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -168,25 +169,26 @@ class SecurityContext {
|
|||||||
*/
|
*/
|
||||||
public function setUser(UserInterface $user)
|
public function setUser(UserInterface $user)
|
||||||
{
|
{
|
||||||
$context = $this->getContext(true);
|
$context = $this->getContext(true);
|
||||||
|
|
||||||
$user->eraseCredentials();
|
$user->eraseCredentials();
|
||||||
|
|
||||||
if ($context === self::CONTEXT_FRONT_OFFICE)
|
if ($context === self::CONTEXT_FRONT_OFFICE)
|
||||||
$this->getSession()->setCustomerUser($user);
|
$this->getSession()->setCustomerUser($user);
|
||||||
else if ($context == self::CONTEXT_BACK_OFFICE)
|
else if ($context == self::CONTEXT_BACK_OFFICE)
|
||||||
$this->getSession()->setAdminUser($user);
|
$this->getSession()->setAdminUser($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the user from the security context
|
* Clear the user from the security context
|
||||||
*/
|
*/
|
||||||
public function clear() {
|
public function clear()
|
||||||
$context = $this->getContext(true);
|
{
|
||||||
|
$context = $this->getContext(true);
|
||||||
|
|
||||||
if ($context === self::CONTEXT_FRONT_OFFICE)
|
if ($context === self::CONTEXT_FRONT_OFFICE)
|
||||||
$this->getSession()->clearCustomerUser();
|
$this->getSession()->clearCustomerUser();
|
||||||
else if ($context == self::CONTEXT_BACK_OFFICE)
|
else if ($context == self::CONTEXT_BACK_OFFICE)
|
||||||
$this->getSession()->clearAdminUser();
|
$this->getSession()->clearAdminUser();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ namespace Thelia\Core\Security\User;
|
|||||||
* @author Franck Allimant <franck@cqfdev.fr>
|
* @author Franck Allimant <franck@cqfdev.fr>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
interface UserInterface {
|
interface UserInterface
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Return the user unique name
|
* Return the user unique name
|
||||||
*/
|
*/
|
||||||
@@ -48,4 +48,4 @@ interface UserInterface {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function eraseCredentials();
|
public function eraseCredentials();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ namespace Thelia\Core\Security\UserProvider;
|
|||||||
use Thelia\Model\Admin;
|
use Thelia\Model\Admin;
|
||||||
use Thelia\Model\AdminQuery;
|
use Thelia\Model\AdminQuery;
|
||||||
|
|
||||||
class AdminUserProvider implements UserProviderInterface {
|
class AdminUserProvider implements UserProviderInterface
|
||||||
|
{
|
||||||
public function getUser($key) {
|
public function getUser($key)
|
||||||
|
{
|
||||||
$admin = AdminQuery::create()
|
$admin = AdminQuery::create()
|
||||||
->filterByLogin($key)
|
->filterByLogin($key)
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
return $admin;
|
return $admin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Thelia\Core\Security\UserProvider;
|
namespace Thelia\Core\Security\UserProvider;
|
||||||
|
|
||||||
|
|
||||||
use Thelia\Action\Customer;
|
use Thelia\Action\Customer;
|
||||||
use Thelia\Model\CustomerQuery;
|
use Thelia\Model\CustomerQuery;
|
||||||
class CustomerUserProvider implements UserProviderInterface {
|
class CustomerUserProvider implements UserProviderInterface
|
||||||
|
{
|
||||||
public function getUser($key) {
|
public function getUser($key)
|
||||||
|
{
|
||||||
$customer = CustomerQuery::create()
|
$customer = CustomerQuery::create()
|
||||||
->filterByEmail($key)
|
->filterByEmail($key)
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
return $customer;
|
return $customer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\Security\UserProvider;
|
namespace Thelia\Core\Security\UserProvider;
|
||||||
|
|
||||||
interface UserProviderInterface {
|
interface UserProviderInterface
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Returns a UserInterface instance
|
* Returns a UserInterface instance
|
||||||
*
|
*
|
||||||
@@ -11,4 +12,3 @@ interface UserProviderInterface {
|
|||||||
*/
|
*/
|
||||||
public function getUser($key);
|
public function getUser($key);
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
@@ -51,7 +51,6 @@ abstract class BaseLoop
|
|||||||
*/
|
*/
|
||||||
protected $securityContext;
|
protected $securityContext;
|
||||||
|
|
||||||
|
|
||||||
protected $args;
|
protected $args;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,11 +76,11 @@ abstract class BaseLoop
|
|||||||
*/
|
*/
|
||||||
protected function getDefaultArgs()
|
protected function getDefaultArgs()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
Argument::createIntTypeArgument('offset', 0),
|
Argument::createIntTypeArgument('offset', 0),
|
||||||
Argument::createIntTypeArgument('page'),
|
Argument::createIntTypeArgument('page'),
|
||||||
Argument::createIntTypeArgument('limit', PHP_INT_MAX),
|
Argument::createIntTypeArgument('limit', PHP_INT_MAX),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,17 +92,17 @@ abstract class BaseLoop
|
|||||||
* @return null
|
* @return null
|
||||||
* @throws \InvalidArgumentException if the parameter is unknown or the method name is not supported.
|
* @throws \InvalidArgumentException if the parameter is unknown or the method name is not supported.
|
||||||
*/
|
*/
|
||||||
public function __call($name, $arguments) {
|
public function __call($name, $arguments)
|
||||||
|
{
|
||||||
|
if (substr($name, 0, 3) == 'get') {
|
||||||
|
|
||||||
if (substr($name, 0, 3) == 'get') {
|
// camelCase to underscore: getNotEmpty -> not_empty
|
||||||
|
$argName = strtolower(preg_replace('/([^A-Z])([A-Z])/', "$1_$2", substr($name, 3)));
|
||||||
|
|
||||||
// camelCase to underscore: getNotEmpty -> not_empty
|
return $this->getArg($argName)->getValue();
|
||||||
$argName = strtolower(preg_replace('/([^A-Z])([A-Z])/', "$1_$2", substr($name, 3)));
|
}
|
||||||
|
|
||||||
return $this->getArg($argName)->getValue();
|
throw new \InvalidArgumentException(sprintf("Unsupported magic method %s. only getArgname() is supported.", $name));
|
||||||
}
|
|
||||||
|
|
||||||
throw new \InvalidArgumentException(sprintf("Unsupported magic method %s. only getArgname() is supported.", $name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,8 +112,8 @@ abstract class BaseLoop
|
|||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException if somùe argument values are missing, or invalid
|
* @throws \InvalidArgumentException if somùe argument values are missing, or invalid
|
||||||
*/
|
*/
|
||||||
public function initializeArgs(array $nameValuePairs) {
|
public function initializeArgs(array $nameValuePairs)
|
||||||
|
{
|
||||||
$faultActor = array();
|
$faultActor = array();
|
||||||
$faultDetails = array();
|
$faultDetails = array();
|
||||||
|
|
||||||
@@ -127,29 +126,26 @@ abstract class BaseLoop
|
|||||||
$value = isset($nameValuePairs[$argument->name]) ? $nameValuePairs[$argument->name] : null;
|
$value = isset($nameValuePairs[$argument->name]) ? $nameValuePairs[$argument->name] : null;
|
||||||
|
|
||||||
/* check if mandatory */
|
/* check if mandatory */
|
||||||
if($value === null && $argument->mandatory) {
|
if ($value === null && $argument->mandatory) {
|
||||||
$faultActor[] = $argument->name;
|
$faultActor[] = $argument->name;
|
||||||
$faultDetails[] = sprintf('"%s" parameter is missing in loop type: %s, name: %s', $argument->name, $loopType, $loopName);
|
$faultDetails[] = sprintf('"%s" parameter is missing in loop type: %s, name: %s', $argument->name, $loopType, $loopName);
|
||||||
}
|
} else if ($value === '' && !$argument->empty) {
|
||||||
else if($value === '' && !$argument->empty) {
|
/* check if empty */
|
||||||
/* check if empty */
|
|
||||||
$faultActor[] = $argument->name;
|
$faultActor[] = $argument->name;
|
||||||
$faultDetails[] = sprintf('"%s" parameter cannot be empty in loop type: %s, name: %s', $argument->name, $loopType, $loopName);
|
$faultDetails[] = sprintf('"%s" parameter cannot be empty in loop type: %s, name: %s', $argument->name, $loopType, $loopName);
|
||||||
}
|
} elseif ($value !== null && !$argument->type->isValid($value)) {
|
||||||
else if($value !== null && !$argument->type->isValid($value)) {
|
/* check type */
|
||||||
/* check type */
|
|
||||||
$faultActor[] = $argument->name;
|
$faultActor[] = $argument->name;
|
||||||
$faultDetails[] = sprintf('Invalid value for "%s" argument in loop type: %s, name: %s', $argument->name, $loopType, $loopName);
|
$faultDetails[] = sprintf('Invalid value for "%s" argument in loop type: %s, name: %s', $argument->name, $loopType, $loopName);
|
||||||
}
|
} else {
|
||||||
else {
|
/* set default */
|
||||||
/* set default */
|
/* did it as last checking for we consider default value is acceptable no matter type or empty restriction */
|
||||||
/* did it as last checking for we consider default value is acceptable no matter type or empty restriction */
|
if ($value === null) {
|
||||||
if($value === null) {
|
$value = $argument->default;
|
||||||
$value = $argument->default;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$argument->setValue($value);
|
$argument->setValue($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($faultActor)) {
|
if (!empty($faultActor)) {
|
||||||
@@ -165,16 +161,16 @@ abstract class BaseLoop
|
|||||||
* @param string $argumentName the argument name
|
* @param string $argumentName the argument name
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException if argument is not found in loop argument list
|
* @throws \InvalidArgumentException if argument is not found in loop argument list
|
||||||
* @return Argument the loop argument.
|
* @return Argument the loop argument.
|
||||||
*/
|
*/
|
||||||
public function getArg($argumentName) {
|
public function getArg($argumentName)
|
||||||
|
{
|
||||||
|
$arg = $this->args->get($argumentName);
|
||||||
|
|
||||||
$arg = $this->args->get($argumentName);
|
if ($arg === null)
|
||||||
|
throw new \InvalidArgumentException("Undefined loop argument '$argumentName'");
|
||||||
|
|
||||||
if ($arg === null)
|
return $arg;
|
||||||
throw new \InvalidArgumentException("Undefined loop argument '$argumentName'");
|
|
||||||
|
|
||||||
return $arg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,11 +179,11 @@ abstract class BaseLoop
|
|||||||
* @param string $argumentName the argument name
|
* @param string $argumentName the argument name
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException if argument is not found in loop argument list
|
* @throws \InvalidArgumentException if argument is not found in loop argument list
|
||||||
* @return Argument the loop argument.
|
* @return Argument the loop argument.
|
||||||
*/
|
*/
|
||||||
public function getArgValue($argumentName) {
|
public function getArgValue($argumentName)
|
||||||
|
{
|
||||||
return $this->getArg($argumentName)->getValue();
|
return $this->getArg($argumentName)->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -198,7 +194,7 @@ abstract class BaseLoop
|
|||||||
*/
|
*/
|
||||||
public function search(ModelCriteria $search, &$pagination = null)
|
public function search(ModelCriteria $search, &$pagination = null)
|
||||||
{
|
{
|
||||||
if($this->getArgValue('page') !== null) {
|
if ($this->getArgValue('page') !== null) {
|
||||||
return $this->searchWithPagination($search, $pagination);
|
return $this->searchWithPagination($search, $pagination);
|
||||||
} else {
|
} else {
|
||||||
return $this->searchWithOffset($search);
|
return $this->searchWithOffset($search);
|
||||||
@@ -212,7 +208,7 @@ abstract class BaseLoop
|
|||||||
*/
|
*/
|
||||||
public function searchWithOffset(ModelCriteria $search)
|
public function searchWithOffset(ModelCriteria $search)
|
||||||
{
|
{
|
||||||
if($this->getArgValue('limit') >= 0) {
|
if ($this->getArgValue('limit') >= 0) {
|
||||||
$search->limit($this->getArgValue('limit'));
|
$search->limit($this->getArgValue('limit'));
|
||||||
}
|
}
|
||||||
$search->offset($this->getArgValue('offset'));
|
$search->offset($this->getArgValue('offset'));
|
||||||
@@ -230,7 +226,7 @@ abstract class BaseLoop
|
|||||||
{
|
{
|
||||||
$pagination = $search->paginate($this->getArgValue('page'), $this->getArgValue('limit'));
|
$pagination = $search->paginate($this->getArgValue('page'), $this->getArgValue('limit'));
|
||||||
|
|
||||||
if($this->getArgValue('page') > $pagination->getLastPage()) {
|
if ($this->getArgValue('page') > $pagination->getLastPage()) {
|
||||||
return array();
|
return array();
|
||||||
} else {
|
} else {
|
||||||
return $pagination;
|
return $pagination;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class LoopResultRow
|
|||||||
|
|
||||||
public function getVars()
|
public function getVars()
|
||||||
{
|
{
|
||||||
return array_keys($this->substitution);
|
return array_keys($this->substitution);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,19 +26,12 @@ namespace Thelia\Core\Template\Loop;
|
|||||||
use Thelia\Core\Template\Loop\Product;
|
use Thelia\Core\Template\Loop\Product;
|
||||||
|
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Propel\Runtime\ActiveQuery\Join;
|
|
||||||
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\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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\AccessoryQuery;
|
use Thelia\Model\AccessoryQuery;
|
||||||
use Thelia\Model\ProductQuery;
|
|
||||||
use Thelia\Model\ConfigQuery;
|
|
||||||
use Thelia\Type\TypeCollection;
|
|
||||||
use Thelia\Type;
|
use Thelia\Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,12 +79,12 @@ class Accessory extends Product
|
|||||||
$order = $this->getOrder();
|
$order = $this->getOrder();
|
||||||
$orderByAccessory = array_search('accessory', $order);
|
$orderByAccessory = array_search('accessory', $order);
|
||||||
$orderByAccessoryReverse = array_search('accessory_reverse', $order);
|
$orderByAccessoryReverse = array_search('accessory_reverse', $order);
|
||||||
if($orderByAccessory !== false) {
|
if ($orderByAccessory !== false) {
|
||||||
$search->orderByPosition(Criteria::ASC);
|
$search->orderByPosition(Criteria::ASC);
|
||||||
$order[$orderByAccessory] = 'given_id';
|
$order[$orderByAccessory] = 'given_id';
|
||||||
$this->args->get('order')->setValue( implode(',', $order) );
|
$this->args->get('order')->setValue( implode(',', $order) );
|
||||||
}
|
}
|
||||||
if($orderByAccessoryReverse !== false) {
|
if ($orderByAccessoryReverse !== false) {
|
||||||
$search->orderByPosition(Criteria::DESC);
|
$search->orderByPosition(Criteria::DESC);
|
||||||
$order[$orderByAccessoryReverse] = 'given_id';
|
$order[$orderByAccessoryReverse] = 'given_id';
|
||||||
$this->args->get('order')->setValue( implode(',', $order) );
|
$this->args->get('order')->setValue( implode(',', $order) );
|
||||||
@@ -107,7 +100,7 @@ class Accessory extends Product
|
|||||||
$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(',', $accessoryIdList) );
|
||||||
} else {
|
} else {
|
||||||
$this->args->get('id')->setValue( implode(',', array_intersect($receivedIdList, $accessoryIdList)) );
|
$this->args->get('id')->setValue( implode(',', array_intersect($receivedIdList, $accessoryIdList)) );
|
||||||
|
|||||||
@@ -30,10 +30,8 @@ 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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\AddressQuery;
|
use Thelia\Model\AddressQuery;
|
||||||
use Thelia\Model\ConfigQuery;
|
|
||||||
use Thelia\Type\TypeCollection;
|
use Thelia\Type\TypeCollection;
|
||||||
use Thelia\Type;
|
use Thelia\Type;
|
||||||
|
|
||||||
@@ -77,7 +75,7 @@ class Address extends BaseLoop
|
|||||||
{
|
{
|
||||||
$search = AddressQuery::create();
|
$search = AddressQuery::create();
|
||||||
|
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
|
|
||||||
if (null !== $id) {
|
if (null !== $id) {
|
||||||
$search->filterById($id, Criteria::IN);
|
$search->filterById($id, Criteria::IN);
|
||||||
@@ -87,7 +85,7 @@ class Address extends BaseLoop
|
|||||||
|
|
||||||
if ($customer === 'current') {
|
if ($customer === 'current') {
|
||||||
$currentCustomer = $this->request->getSession()->getCustomerUser();
|
$currentCustomer = $this->request->getSession()->getCustomerUser();
|
||||||
if($currentCustomer === null) {
|
if ($currentCustomer === null) {
|
||||||
return new LoopResult();
|
return new LoopResult();
|
||||||
} else {
|
} else {
|
||||||
$search->filterByCustomerId($currentCustomer->getId(), Criteria::EQUAL);
|
$search->filterByCustomerId($currentCustomer->getId(), Criteria::EQUAL);
|
||||||
@@ -100,7 +98,7 @@ class Address extends BaseLoop
|
|||||||
|
|
||||||
if ($default === true) {
|
if ($default === true) {
|
||||||
$search->filterByIsDefault(1, Criteria::EQUAL);
|
$search->filterByIsDefault(1, Criteria::EQUAL);
|
||||||
} elseif($default === false) {
|
} elseif ($default === false) {
|
||||||
$search->filterByIsDefault(1, Criteria::NOT_EQUAL);
|
$search->filterByIsDefault(1, Criteria::NOT_EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,4 +136,4 @@ class Address extends BaseLoop
|
|||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,12 +51,14 @@ class Argument
|
|||||||
$this->setValue($value);
|
$this->setValue($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValue() {
|
public function getValue()
|
||||||
return $this->type->getFormattedValue($this->value);
|
{
|
||||||
|
return $this->type->getFormattedValue($this->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setValue($value) {
|
public function setValue($value)
|
||||||
$this->value = $value === null ? null : (string)$value;
|
{
|
||||||
|
$this->value = $value === null ? null : (string) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createAnyTypeArgument($name, $default=null, $mandatory=false, $empty=true)
|
public static function createAnyTypeArgument($name, $default=null, $mandatory=false, $empty=true)
|
||||||
@@ -113,15 +115,15 @@ class Argument
|
|||||||
|
|
||||||
public static function createBooleanOrBothTypeArgument($name, $default=null, $mandatory=false, $empty=true)
|
public static function createBooleanOrBothTypeArgument($name, $default=null, $mandatory=false, $empty=true)
|
||||||
{
|
{
|
||||||
return new Argument(
|
return new Argument(
|
||||||
$name,
|
$name,
|
||||||
new TypeCollection(
|
new TypeCollection(
|
||||||
new Type\BooleanOrBothType()
|
new Type\BooleanOrBothType()
|
||||||
),
|
),
|
||||||
$default,
|
$default,
|
||||||
$mandatory,
|
$mandatory,
|
||||||
$empty
|
$empty
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createIntListTypeArgument($name, $default=null, $mandatory=false, $empty=true)
|
public static function createIntListTypeArgument($name, $default=null, $mandatory=false, $empty=true)
|
||||||
|
|||||||
@@ -37,12 +37,14 @@ class ArgumentCollection implements \Iterator
|
|||||||
$this->addArguments(func_get_args(), true);
|
$this->addArguments(func_get_args(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasKey($key) {
|
public function hasKey($key)
|
||||||
return isset($this->arguments[$key]);
|
{
|
||||||
|
return isset($this->arguments[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($key) {
|
public function get($key)
|
||||||
return $this->hasKey($key) ? $this->arguments[$key] : null;
|
{
|
||||||
|
return $this->hasKey($key) ? $this->arguments[$key] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isEmpty()
|
public function isEmpty()
|
||||||
@@ -51,14 +53,14 @@ class ArgumentCollection implements \Iterator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $argumentList
|
* @param array $argumentList
|
||||||
* @param $force
|
* @param $force
|
||||||
*
|
*
|
||||||
* @return ArgumentCollection
|
* @return ArgumentCollection
|
||||||
*/
|
*/
|
||||||
public function addArguments(array $argumentList, $force = true)
|
public function addArguments(array $argumentList, $force = true)
|
||||||
{
|
{
|
||||||
foreach($argumentList as $argument) {
|
foreach ($argumentList as $argument) {
|
||||||
$this->addArgument($argument, $force);
|
$this->addArgument($argument, $force);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +75,7 @@ class ArgumentCollection implements \Iterator
|
|||||||
*/
|
*/
|
||||||
public function addArgument(Argument $argument, $force = true)
|
public function addArgument(Argument $argument, $force = true)
|
||||||
{
|
{
|
||||||
if(isset($this->arguments[$argument->name]) && ! $force) {
|
if (isset($this->arguments[$argument->name]) && ! $force) {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,11 +30,6 @@ 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\Type\TypeCollection;
|
|
||||||
use Thelia\Type;
|
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @package Thelia\Core\Template\Loop
|
* @package Thelia\Core\Template\Loop
|
||||||
@@ -46,24 +41,24 @@ class Auth extends BaseLoop
|
|||||||
public function getArgDefinitions()
|
public function getArgDefinitions()
|
||||||
{
|
{
|
||||||
return new ArgumentCollection(
|
return new ArgumentCollection(
|
||||||
Argument::createAnyTypeArgument('roles', null, true),
|
Argument::createAnyTypeArgument('roles', null, true),
|
||||||
Argument::createAnyTypeArgument('permissions'),
|
Argument::createAnyTypeArgument('permissions'),
|
||||||
Argument::createAnyTypeArgument('context', 'front', false)
|
Argument::createAnyTypeArgument('context', 'front', false)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _explode($commaSeparatedValues)
|
private function _explode($commaSeparatedValues)
|
||||||
{
|
{
|
||||||
|
|
||||||
$array = explode(',', $commaSeparatedValues);
|
$array = explode(',', $commaSeparatedValues);
|
||||||
|
|
||||||
if (array_walk($array, function(&$item) {
|
if (array_walk($array, function(&$item) {
|
||||||
$item = strtoupper(trim($item));
|
$item = strtoupper(trim($item));
|
||||||
})) {
|
})) {
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,25 +68,24 @@ class Auth extends BaseLoop
|
|||||||
*/
|
*/
|
||||||
public function exec(&$pagination)
|
public function exec(&$pagination)
|
||||||
{
|
{
|
||||||
$context = $this->getContext();
|
$context = $this->getContext();
|
||||||
$roles = $this->_explode($this->getRoles());
|
$roles = $this->_explode($this->getRoles());
|
||||||
$permissions = $this->_explode($this->getPermissions());
|
$permissions = $this->_explode($this->getPermissions());
|
||||||
|
|
||||||
$loopResult = new LoopResult();
|
$loopResult = new LoopResult();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->securityContext->setContext($context);
|
$this->securityContext->setContext($context);
|
||||||
|
|
||||||
if (true === $this->securityContext->isGranted($roles, $permissions == null ? array() : $permissions)) {
|
if (true === $this->securityContext->isGranted($roles, $permissions == null ? array() : $permissions)) {
|
||||||
|
|
||||||
// Create an empty row: loop is no longer empty :)
|
// Create an empty row: loop is no longer empty :)
|
||||||
$loopResult->addRow(new LoopResultRow());
|
$loopResult->addRow(new LoopResultRow());
|
||||||
}
|
}
|
||||||
}
|
} catch (\Exception $ex) {
|
||||||
catch (\Exception $ex) {
|
// Not granted, loop is empty
|
||||||
// Not granted, loop is empty
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\Template\Loop;
|
namespace Thelia\Core\Template\Loop;
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
class Cart extends BaseLoop {
|
class Cart extends BaseLoop
|
||||||
|
{
|
||||||
use \Thelia\Cart\CartTrait;
|
use \Thelia\Cart\CartTrait;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -74,11 +74,10 @@ class Cart extends BaseLoop {
|
|||||||
$result = new LoopResult();
|
$result = new LoopResult();
|
||||||
$cart = $this->getCart($this->request);
|
$cart = $this->getCart($this->request);
|
||||||
|
|
||||||
if($cart === null) {
|
if ($cart === null) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$cartItems = $cart->getCartItems();
|
$cartItems = $cart->getCartItems();
|
||||||
|
|
||||||
foreach ($cartItems as $cartItem) {
|
foreach ($cartItems as $cartItem) {
|
||||||
@@ -99,5 +98,4 @@ class Cart extends BaseLoop {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ 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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\CategoryQuery;
|
use Thelia\Model\CategoryQuery;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
@@ -95,7 +94,7 @@ class Category extends BaseLoop
|
|||||||
{
|
{
|
||||||
$search = CategoryQuery::create();
|
$search = CategoryQuery::create();
|
||||||
|
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
|
|
||||||
if (!is_null($id)) {
|
if (!is_null($id)) {
|
||||||
$search->filterById($id, Criteria::IN);
|
$search->filterById($id, Criteria::IN);
|
||||||
@@ -107,8 +106,7 @@ class Category extends BaseLoop
|
|||||||
$search->filterByParent($parent);
|
$search->filterByParent($parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$current = $this->getCurrent();
|
||||||
$current = $this->getCurrent();
|
|
||||||
|
|
||||||
if ($current === true) {
|
if ($current === true) {
|
||||||
$search->filterById($this->request->get("category_id"));
|
$search->filterById($this->request->get("category_id"));
|
||||||
@@ -116,7 +114,6 @@ class Category extends BaseLoop
|
|||||||
$search->filterById($this->request->get("category_id"), Criteria::NOT_IN);
|
$search->filterById($this->request->get("category_id"), Criteria::NOT_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$exclude = $this->getExclude();
|
$exclude = $this->getExclude();
|
||||||
|
|
||||||
if (!is_null($exclude)) {
|
if (!is_null($exclude)) {
|
||||||
@@ -124,11 +121,11 @@ class Category extends BaseLoop
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getVisible() != BooleanOrBothType::ANY)
|
if ($this->getVisible() != BooleanOrBothType::ANY)
|
||||||
$search->filterByVisible($this->getVisible() ? 1 : 0);
|
$search->filterByVisible($this->getVisible() ? 1 : 0);
|
||||||
|
|
||||||
$orders = $this->getOrder();
|
$orders = $this->getOrder();
|
||||||
|
|
||||||
foreach($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
switch ($order) {
|
switch ($order) {
|
||||||
case "alpha":
|
case "alpha":
|
||||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
|
$search->addAscendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
|
||||||
@@ -171,31 +168,30 @@ class Category extends BaseLoop
|
|||||||
|
|
||||||
if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue;
|
if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue;
|
||||||
|
|
||||||
|
|
||||||
$loopResultRow = new LoopResultRow();
|
$loopResultRow = new LoopResultRow();
|
||||||
|
|
||||||
$loopResultRow
|
$loopResultRow
|
||||||
->set("ID", $category->getId())
|
->set("ID", $category->getId())
|
||||||
->set("TITLE",$category->getTitle())
|
->set("TITLE",$category->getTitle())
|
||||||
->set("CHAPO", $category->getChapo())
|
->set("CHAPO", $category->getChapo())
|
||||||
->set("DESCRIPTION", $category->getDescription())
|
->set("DESCRIPTION", $category->getDescription())
|
||||||
->set("POSTSCRIPTUM", $category->getPostscriptum())
|
->set("POSTSCRIPTUM", $category->getPostscriptum())
|
||||||
->set("PARENT", $category->getParent())
|
->set("PARENT", $category->getParent())
|
||||||
->set("URL", $category->getUrl())
|
->set("URL", $category->getUrl())
|
||||||
->set("PRODUCT_COUNT", $category->countChild())
|
->set("PRODUCT_COUNT", $category->countChild())
|
||||||
->set("VISIBLE", $category->getVisible() ? "1" : "0")
|
->set("VISIBLE", $category->getVisible() ? "1" : "0")
|
||||||
->set("POSITION", $category->getPosition())
|
->set("POSITION", $category->getPosition())
|
||||||
|
|
||||||
->set("CREATE_DATE", $category->getCreatedAt())
|
->set("CREATE_DATE", $category->getCreatedAt())
|
||||||
->set("UPDATE_DATE", $category->getUpdatedAt())
|
->set("UPDATE_DATE", $category->getUpdatedAt())
|
||||||
->set("VERSION", $category->getVersion())
|
->set("VERSION", $category->getVersion())
|
||||||
->set("VERSION_DATE", $category->getVersionCreatedAt())
|
->set("VERSION_DATE", $category->getVersionCreatedAt())
|
||||||
->set("VERSION_AUTHOR", $category->getVersionCreatedBy())
|
->set("VERSION_AUTHOR", $category->getVersionCreatedBy())
|
||||||
;
|
;
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
$loopResult->addRow($loopResultRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,18 +23,14 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\Template\Loop;
|
namespace Thelia\Core\Template\Loop;
|
||||||
|
|
||||||
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\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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\CategoryQuery;
|
use Thelia\Model\CategoryQuery;
|
||||||
use Thelia\Model\ConfigQuery;
|
|
||||||
use Thelia\Type\TypeCollection;
|
|
||||||
use Thelia\Type;
|
use Thelia\Type;
|
||||||
use Thelia\Type\BooleanOrBothType;
|
use Thelia\Type\BooleanOrBothType;
|
||||||
|
|
||||||
@@ -69,7 +65,7 @@ class CategoryPath extends BaseLoop
|
|||||||
Argument::createIntTypeArgument('category', null, true),
|
Argument::createIntTypeArgument('category', null, true),
|
||||||
Argument::createIntTypeArgument('depth'),
|
Argument::createIntTypeArgument('depth'),
|
||||||
Argument::createIntTypeArgument('level'),
|
Argument::createIntTypeArgument('level'),
|
||||||
Argument::createBooleanOrBothTypeArgument('visible', true, false)
|
Argument::createBooleanOrBothTypeArgument('visible', true, false)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,50 +76,49 @@ class CategoryPath extends BaseLoop
|
|||||||
*/
|
*/
|
||||||
public function exec(&$pagination)
|
public function exec(&$pagination)
|
||||||
{
|
{
|
||||||
$id = $this->getCategory();
|
$id = $this->getCategory();
|
||||||
$visible = $this->getVisible();
|
$visible = $this->getVisible();
|
||||||
|
|
||||||
$search = CategoryQuery::create();
|
$search = CategoryQuery::create();
|
||||||
$search->filterById($id);
|
$search->filterById($id);
|
||||||
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
|
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
||||||
$ids = array();
|
$ids = array();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$category = $search->findOne();
|
$category = $search->findOne();
|
||||||
|
|
||||||
if ($category != null) {
|
if ($category != null) {
|
||||||
|
|
||||||
$loopResultRow = new LoopResultRow();
|
$loopResultRow = new LoopResultRow();
|
||||||
|
|
||||||
$loopResultRow
|
$loopResultRow
|
||||||
->set("TITLE",$category->getTitle())
|
->set("TITLE",$category->getTitle())
|
||||||
->set("URL", $category->getUrl())
|
->set("URL", $category->getUrl())
|
||||||
->set("ID", $category->getId())
|
->set("ID", $category->getId())
|
||||||
;
|
;
|
||||||
|
|
||||||
$results[] = $loopResultRow;
|
$results[] = $loopResultRow;
|
||||||
|
|
||||||
$parent = $category->getParent();
|
$parent = $category->getParent();
|
||||||
|
|
||||||
if ($parent > 0) {
|
if ($parent > 0) {
|
||||||
|
|
||||||
// Prevent circular refererences
|
// Prevent circular refererences
|
||||||
if (in_array($parent, $ids)) {
|
if (in_array($parent, $ids)) {
|
||||||
throw new \LogicException(sprintf("Circular reference detected in category ID=%d hierarchy (category ID=%d appears more than one times in path)", $id, $parent));
|
throw new \LogicException(sprintf("Circular reference detected in category ID=%d hierarchy (category ID=%d appears more than one times in path)", $id, $parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
$ids[] = $parent;
|
$ids[] = $parent;
|
||||||
|
|
||||||
$search = CategoryQuery::create();
|
$search = CategoryQuery::create();
|
||||||
$search->filterById($parent);
|
$search->filterById($parent);
|
||||||
if ($visible == true) $search->filterByVisible($visible);
|
if ($visible == true) $search->filterByVisible($visible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} 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);
|
$results = array_reverse($results);
|
||||||
@@ -134,4 +129,4 @@ class CategoryPath extends BaseLoop
|
|||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,8 @@ 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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\CategoryQuery;
|
use Thelia\Model\CategoryQuery;
|
||||||
use Thelia\Model\ConfigQuery;
|
|
||||||
use Thelia\Type\TypeCollection;
|
|
||||||
use Thelia\Type;
|
use Thelia\Type;
|
||||||
use Thelia\Type\BooleanOrBothType;
|
use Thelia\Type\BooleanOrBothType;
|
||||||
|
|
||||||
@@ -59,45 +56,45 @@ class CategoryTree extends BaseLoop
|
|||||||
return new ArgumentCollection(
|
return new ArgumentCollection(
|
||||||
Argument::createIntTypeArgument('category', null, true),
|
Argument::createIntTypeArgument('category', null, true),
|
||||||
Argument::createIntTypeArgument('depth', PHP_INT_MAX),
|
Argument::createIntTypeArgument('depth', PHP_INT_MAX),
|
||||||
Argument::createBooleanOrBothTypeArgument('visible', true, false),
|
Argument::createBooleanOrBothTypeArgument('visible', true, false),
|
||||||
Argument::createIntListTypeArgument('exclude', array())
|
Argument::createIntListTypeArgument('exclude', array())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// changement de rubrique
|
// changement de rubrique
|
||||||
protected function buildCategoryTree($parent, $visible, $level, $max_level, array $exclude, LoopResult &$loopResult) {
|
protected function buildCategoryTree($parent, $visible, $level, $max_level, array $exclude, LoopResult &$loopResult)
|
||||||
|
{
|
||||||
|
if ($level > $max_level) return;
|
||||||
|
|
||||||
if ($level > $max_level) return;
|
$search = CategoryQuery::create();
|
||||||
|
|
||||||
$search = CategoryQuery::create();
|
$search->filterByParent($parent);
|
||||||
|
|
||||||
$search->filterByParent($parent);
|
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
|
||||||
|
|
||||||
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
|
$search->filterById($exclude, Criteria::NOT_IN);
|
||||||
|
|
||||||
$search->filterById($exclude, Criteria::NOT_IN);
|
$search->orderByPosition(Criteria::ASC);
|
||||||
|
|
||||||
$search->orderByPosition(Criteria::ASC);
|
$results = $search->find();
|
||||||
|
|
||||||
$results = $search->find();
|
foreach ($results as $result) {
|
||||||
|
|
||||||
foreach($results as $result) {
|
$loopResultRow = new LoopResultRow();
|
||||||
|
|
||||||
$loopResultRow = new LoopResultRow();
|
$loopResultRow
|
||||||
|
->set("ID", $result->getId())
|
||||||
|
->set("TITLE",$result->getTitle())
|
||||||
|
->set("PARENT", $result->getParent())
|
||||||
|
->set("URL", $result->getUrl())
|
||||||
|
->set("VISIBLE", $result->getVisible() ? "1" : "0")
|
||||||
|
->set("LEVEL", $level)
|
||||||
|
;
|
||||||
|
|
||||||
$loopResultRow
|
$loopResult->addRow($loopResultRow);
|
||||||
->set("ID", $result->getId())
|
|
||||||
->set("TITLE",$result->getTitle())
|
|
||||||
->set("PARENT", $result->getParent())
|
|
||||||
->set("URL", $result->getUrl())
|
|
||||||
->set("VISIBLE", $result->getVisible() ? "1" : "0")
|
|
||||||
->set("LEVEL", $level)
|
|
||||||
;
|
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
$this->buildCategoryTree($result->getId(), $visible, 1 + $level, $max_level, $exclude, $loopResult);
|
||||||
|
}
|
||||||
$this->buildCategoryTree($result->getId(), $visible, 1 + $level, $max_level, $exclude, $loopResult);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,17 +104,17 @@ class CategoryTree extends BaseLoop
|
|||||||
*/
|
*/
|
||||||
public function exec(&$pagination)
|
public function exec(&$pagination)
|
||||||
{
|
{
|
||||||
$id = $this->getCategory();
|
$id = $this->getCategory();
|
||||||
$depth = $this->getDepth();
|
$depth = $this->getDepth();
|
||||||
$visible = $this->getVisible();
|
$visible = $this->getVisible();
|
||||||
$exclude = $this->getExclude();
|
$exclude = $this->getExclude();
|
||||||
|
|
||||||
//echo "exclude=".print_r($exclude);
|
//echo "exclude=".print_r($exclude);
|
||||||
|
|
||||||
$loopResult = new LoopResult();
|
$loopResult = new LoopResult();
|
||||||
|
|
||||||
$this->buildCategoryTree($id, $visible, 0, $depth, $exclude, $loopResult);
|
$this->buildCategoryTree($id, $visible, 0, $depth, $exclude, $loopResult);
|
||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,16 +24,13 @@
|
|||||||
namespace Thelia\Core\Template\Loop;
|
namespace Thelia\Core\Template\Loop;
|
||||||
|
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Propel\Runtime\ActiveQuery\Join;
|
|
||||||
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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\Base\FeatureContentQuery;
|
|
||||||
use Thelia\Model\FolderQuery;
|
use Thelia\Model\FolderQuery;
|
||||||
use Thelia\Model\Map\ContentTableMap;
|
use Thelia\Model\Map\ContentTableMap;
|
||||||
use Thelia\Model\ContentFolderQuery;
|
use Thelia\Model\ContentFolderQuery;
|
||||||
@@ -101,8 +98,8 @@ class Content extends BaseLoop
|
|||||||
|
|
||||||
$depth = $this->getDepth();
|
$depth = $this->getDepth();
|
||||||
|
|
||||||
if(null !== $depth) {
|
if (null !== $depth) {
|
||||||
foreach(FolderQuery::findAllChild($folder, $depth) as $subFolder) {
|
foreach (FolderQuery::findAllChild($folder, $depth) as $subFolder) {
|
||||||
$folders->prepend($subFolder);
|
$folders->prepend($subFolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,7 +114,7 @@ class Content extends BaseLoop
|
|||||||
|
|
||||||
if ($current === true) {
|
if ($current === true) {
|
||||||
$search->filterById($this->request->get("content_id"));
|
$search->filterById($this->request->get("content_id"));
|
||||||
} elseif($current === false) {
|
} elseif ($current === false) {
|
||||||
$search->filterById($this->request->get("content_id"), Criteria::NOT_IN);
|
$search->filterById($this->request->get("content_id"), Criteria::NOT_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +131,7 @@ class Content extends BaseLoop
|
|||||||
)->find(),
|
)->find(),
|
||||||
Criteria::IN
|
Criteria::IN
|
||||||
);
|
);
|
||||||
} elseif($current_folder === false) {
|
} elseif ($current_folder === false) {
|
||||||
$search->filterByFolder(
|
$search->filterByFolder(
|
||||||
FolderQuery::create()->filterByContent(
|
FolderQuery::create()->filterByContent(
|
||||||
ContentFolderQuery::create()->filterByContentId(
|
ContentFolderQuery::create()->filterByContentId(
|
||||||
@@ -153,7 +150,7 @@ class Content extends BaseLoop
|
|||||||
|
|
||||||
$orders = $this->getOrder();
|
$orders = $this->getOrder();
|
||||||
|
|
||||||
foreach($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
switch ($order) {
|
switch ($order) {
|
||||||
case "alpha":
|
case "alpha":
|
||||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\ContentI18nTableMap::TITLE);
|
$search->addAscendingOrderByColumn(\Thelia\Model\Map\ContentI18nTableMap::TITLE);
|
||||||
@@ -174,7 +171,7 @@ class Content extends BaseLoop
|
|||||||
case "given_id":
|
case "given_id":
|
||||||
if(null === $id)
|
if(null === $id)
|
||||||
throw new \InvalidArgumentException('Given_id order cannot be set without `id` argument');
|
throw new \InvalidArgumentException('Given_id order cannot be set without `id` argument');
|
||||||
foreach($id as $singleId) {
|
foreach ($id as $singleId) {
|
||||||
$givenIdMatched = 'given_id_matched_' . $singleId;
|
$givenIdMatched = 'given_id_matched_' . $singleId;
|
||||||
$search->withColumn(ContentTableMap::ID . "='$singleId'", $givenIdMatched);
|
$search->withColumn(ContentTableMap::ID . "='$singleId'", $givenIdMatched);
|
||||||
$search->orderBy($givenIdMatched, Criteria::DESC);
|
$search->orderBy($givenIdMatched, Criteria::DESC);
|
||||||
@@ -223,12 +220,12 @@ class Content extends BaseLoop
|
|||||||
$loopResultRow = new LoopResultRow();
|
$loopResultRow = new LoopResultRow();
|
||||||
|
|
||||||
$loopResultRow->set("ID", $content->getId())
|
$loopResultRow->set("ID", $content->getId())
|
||||||
->set("TITLE",$content->getTitle())
|
->set("TITLE",$content->getTitle())
|
||||||
->set("CHAPO", $content->getChapo())
|
->set("CHAPO", $content->getChapo())
|
||||||
->set("DESCRIPTION", $content->getDescription())
|
->set("DESCRIPTION", $content->getDescription())
|
||||||
->set("POSTSCRIPTUM", $content->getPostscriptum())
|
->set("POSTSCRIPTUM", $content->getPostscriptum())
|
||||||
->set("POSITION", $content->getPosition())
|
->set("POSITION", $content->getPosition())
|
||||||
;
|
;
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
$loopResult->addRow($loopResultRow);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,9 @@ 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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\CountryQuery;
|
use Thelia\Model\CountryQuery;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
use Thelia\Type\TypeCollection;
|
|
||||||
use Thelia\Type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -71,7 +68,7 @@ class Country extends BaseLoop
|
|||||||
{
|
{
|
||||||
$search = CountryQuery::create();
|
$search = CountryQuery::create();
|
||||||
|
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
|
|
||||||
if (null !== $id) {
|
if (null !== $id) {
|
||||||
$search->filterById($id, Criteria::IN);
|
$search->filterById($id, Criteria::IN);
|
||||||
@@ -131,4 +128,4 @@ class Country extends BaseLoop
|
|||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,10 +30,8 @@ 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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\CustomerQuery;
|
use Thelia\Model\CustomerQuery;
|
||||||
use Thelia\Model\ConfigQuery;
|
|
||||||
use Thelia\Type\TypeCollection;
|
use Thelia\Type\TypeCollection;
|
||||||
use Thelia\Type;
|
use Thelia\Type;
|
||||||
|
|
||||||
@@ -76,18 +74,18 @@ class Customer extends BaseLoop
|
|||||||
{
|
{
|
||||||
$search = CustomerQuery::create();
|
$search = CustomerQuery::create();
|
||||||
|
|
||||||
$current = $this->getCurrent();
|
$current = $this->getCurrent();
|
||||||
|
|
||||||
if ($current === true) {
|
if ($current === true) {
|
||||||
$currentCustomer = $this->request->getSession()->getCustomerUser();
|
$currentCustomer = $this->request->getSession()->getCustomerUser();
|
||||||
if($currentCustomer === null) {
|
if ($currentCustomer === null) {
|
||||||
return new LoopResult();
|
return new LoopResult();
|
||||||
} else {
|
} else {
|
||||||
$search->filterById($currentCustomer->getId(), Criteria::EQUAL);
|
$search->filterById($currentCustomer->getId(), Criteria::EQUAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
|
|
||||||
if (null !== $id) {
|
if (null !== $id) {
|
||||||
$search->filterById($id, Criteria::IN);
|
$search->filterById($id, Criteria::IN);
|
||||||
@@ -103,7 +101,7 @@ class Customer extends BaseLoop
|
|||||||
|
|
||||||
if ($reseller === true) {
|
if ($reseller === true) {
|
||||||
$search->filterByReseller(1, Criteria::EQUAL);
|
$search->filterByReseller(1, Criteria::EQUAL);
|
||||||
} else if($reseller === false) {
|
} elseif ($reseller === false) {
|
||||||
$search->filterByReseller(0, Criteria::EQUAL);
|
$search->filterByReseller(0, Criteria::EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,4 +132,4 @@ class Customer extends BaseLoop
|
|||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,14 +24,12 @@
|
|||||||
namespace Thelia\Core\Template\Loop;
|
namespace Thelia\Core\Template\Loop;
|
||||||
|
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Propel\Runtime\ActiveQuery\Join;
|
|
||||||
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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\Base\CategoryQuery;
|
use Thelia\Model\Base\CategoryQuery;
|
||||||
use Thelia\Model\Base\ProductCategoryQuery;
|
use Thelia\Model\Base\ProductCategoryQuery;
|
||||||
@@ -102,17 +100,17 @@ class Feature extends BaseLoop
|
|||||||
$product = $this->getProduct();
|
$product = $this->getProduct();
|
||||||
$category = $this->getCategory();
|
$category = $this->getCategory();
|
||||||
|
|
||||||
if(null !== $product) {
|
if (null !== $product) {
|
||||||
$productCategories = ProductCategoryQuery::create()->select(array(ProductCategoryTableMap::CATEGORY_ID))->filterByProductId($product, Criteria::IN)->find()->getData();
|
$productCategories = ProductCategoryQuery::create()->select(array(ProductCategoryTableMap::CATEGORY_ID))->filterByProductId($product, Criteria::IN)->find()->getData();
|
||||||
|
|
||||||
if(null === $category) {
|
if (null === $category) {
|
||||||
$category = $productCategories;
|
$category = $productCategories;
|
||||||
} else {
|
} else {
|
||||||
$category = array_merge($category, $productCategories);
|
$category = array_merge($category, $productCategories);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(null !== $category) {
|
if (null !== $category) {
|
||||||
$search->filterByCategory(
|
$search->filterByCategory(
|
||||||
CategoryQuery::create()->filterById($category)->find(),
|
CategoryQuery::create()->filterById($category)->find(),
|
||||||
Criteria::IN
|
Criteria::IN
|
||||||
@@ -121,7 +119,7 @@ class Feature extends BaseLoop
|
|||||||
|
|
||||||
$orders = $this->getOrder();
|
$orders = $this->getOrder();
|
||||||
|
|
||||||
foreach($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
switch ($order) {
|
switch ($order) {
|
||||||
case "alpha":
|
case "alpha":
|
||||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE);
|
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE);
|
||||||
@@ -166,4 +164,4 @@ class Feature extends BaseLoop
|
|||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,14 +24,12 @@
|
|||||||
namespace Thelia\Core\Template\Loop;
|
namespace Thelia\Core\Template\Loop;
|
||||||
|
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Propel\Runtime\ActiveQuery\Join;
|
|
||||||
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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\Base\FeatureAvQuery;
|
use Thelia\Model\Base\FeatureAvQuery;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
@@ -91,13 +89,13 @@ class FeatureAvailable extends BaseLoop
|
|||||||
|
|
||||||
$feature = $this->getFeature();
|
$feature = $this->getFeature();
|
||||||
|
|
||||||
if(null !== $feature) {
|
if (null !== $feature) {
|
||||||
$search->filterByFeatureId($feature, Criteria::IN);
|
$search->filterByFeatureId($feature, Criteria::IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
$orders = $this->getOrder();
|
$orders = $this->getOrder();
|
||||||
|
|
||||||
foreach($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
switch ($order) {
|
switch ($order) {
|
||||||
case "alpha":
|
case "alpha":
|
||||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureAvI18nTableMap::TITLE);
|
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureAvI18nTableMap::TITLE);
|
||||||
@@ -142,4 +140,4 @@ class FeatureAvailable extends BaseLoop
|
|||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,14 +24,12 @@
|
|||||||
namespace Thelia\Core\Template\Loop;
|
namespace Thelia\Core\Template\Loop;
|
||||||
|
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Propel\Runtime\ActiveQuery\Join;
|
|
||||||
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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\Base\FeatureProductQuery;
|
use Thelia\Model\Base\FeatureProductQuery;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
@@ -94,18 +92,18 @@ class FeatureValue extends BaseLoop
|
|||||||
}
|
}
|
||||||
|
|
||||||
$excludeFeatureAvailable = $this->getExclude_feature_available();
|
$excludeFeatureAvailable = $this->getExclude_feature_available();
|
||||||
if($excludeFeatureAvailable == true) {
|
if ($excludeFeatureAvailable == true) {
|
||||||
$search->filterByFeatureAvId(null, Criteria::NULL);
|
$search->filterByFeatureAvId(null, Criteria::NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$excludeDefaultValues = $this->getExclude_default_values();
|
$excludeDefaultValues = $this->getExclude_default_values();
|
||||||
if($excludeDefaultValues == true) {
|
if ($excludeDefaultValues == true) {
|
||||||
$search->filterByByDefault(null, Criteria::NULL);
|
$search->filterByByDefault(null, Criteria::NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$orders = $this->getOrder();
|
$orders = $this->getOrder();
|
||||||
|
|
||||||
foreach($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
switch ($order) {
|
switch ($order) {
|
||||||
case "alpha":
|
case "alpha":
|
||||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE);
|
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE);
|
||||||
@@ -150,4 +148,4 @@ class FeatureValue extends BaseLoop
|
|||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,9 +30,6 @@ 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\Type\TypeCollection;
|
|
||||||
use Thelia\Type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @package Thelia\Core\Template\Loop
|
* @package Thelia\Core\Template\Loop
|
||||||
@@ -44,8 +41,8 @@ class Feed extends BaseLoop
|
|||||||
public function getArgDefinitions()
|
public function getArgDefinitions()
|
||||||
{
|
{
|
||||||
return new ArgumentCollection(
|
return new ArgumentCollection(
|
||||||
Argument::createAnyTypeArgument('url', null, true),
|
Argument::createAnyTypeArgument('url', null, true),
|
||||||
Argument::createIntTypeArgument('timeout', 10)
|
Argument::createIntTypeArgument('timeout', 10)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,13 +53,13 @@ class Feed extends BaseLoop
|
|||||||
*/
|
*/
|
||||||
public function exec(&$pagination)
|
public function exec(&$pagination)
|
||||||
{
|
{
|
||||||
$cachedir = THELIA_ROOT . 'cache/feeds';
|
$cachedir = THELIA_ROOT . 'cache/feeds';
|
||||||
|
|
||||||
if (! is_dir($cachedir)) {
|
if (! is_dir($cachedir)) {
|
||||||
if (! mkdir($cachedir)) {
|
if (! mkdir($cachedir)) {
|
||||||
throw new \Exception(sprintf("Failed to create cache directory '%s'", $cachedir));
|
throw new \Exception(sprintf("Failed to create cache directory '%s'", $cachedir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$feed = new \SimplePie($this->getUrl(), THELIA_ROOT . 'cache/feeds');
|
$feed = new \SimplePie($this->getUrl(), THELIA_ROOT . 'cache/feeds');
|
||||||
|
|
||||||
@@ -78,29 +75,29 @@ class Feed extends BaseLoop
|
|||||||
|
|
||||||
$loopResult = new LoopResult();
|
$loopResult = new LoopResult();
|
||||||
|
|
||||||
for($idx = 0; $idx < $limit; $idx++) {
|
for ($idx = 0; $idx < $limit; $idx++) {
|
||||||
|
|
||||||
$item = $items[$idx];
|
$item = $items[$idx];
|
||||||
|
|
||||||
$link = $item->get_permalink();
|
$link = $item->get_permalink();
|
||||||
|
|
||||||
$title = $item->get_title();
|
$title = $item->get_title();
|
||||||
$author = $item->get_author();
|
$author = $item->get_author();
|
||||||
$description = $item->get_description();
|
$description = $item->get_description();
|
||||||
|
|
||||||
$date = $item->get_date('d/m/Y');
|
$date = $item->get_date('d/m/Y');
|
||||||
|
|
||||||
$loopResultRow = new LoopResultRow();
|
$loopResultRow = new LoopResultRow();
|
||||||
|
|
||||||
$loopResultRow->set("URL", $item->get_permalink());
|
$loopResultRow->set("URL", $item->get_permalink());
|
||||||
$loopResultRow->set("TITLE", $item->get_title());
|
$loopResultRow->set("TITLE", $item->get_title());
|
||||||
$loopResultRow->set("AUTHOR", $item->get_author());
|
$loopResultRow->set("AUTHOR", $item->get_author());
|
||||||
$loopResultRow->set("DESCRIPTION", $item->get_description());
|
$loopResultRow->set("DESCRIPTION", $item->get_description());
|
||||||
$loopResultRow->set("DATE", $item->get_date('d/m/Y')); // FIXME - date format should be an intl parameter
|
$loopResultRow->set("DATE", $item->get_date('d/m/Y')); // FIXME - date format should be an intl parameter
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
$loopResult->addRow($loopResultRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ 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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\FolderQuery;
|
use Thelia\Model\FolderQuery;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
@@ -77,7 +76,7 @@ class Folder extends BaseLoop
|
|||||||
{
|
{
|
||||||
$search = FolderQuery::create();
|
$search = FolderQuery::create();
|
||||||
|
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
|
|
||||||
if (!is_null($id)) {
|
if (!is_null($id)) {
|
||||||
$search->filterById($id, Criteria::IN);
|
$search->filterById($id, Criteria::IN);
|
||||||
@@ -89,8 +88,7 @@ class Folder extends BaseLoop
|
|||||||
$search->filterByParent($parent);
|
$search->filterByParent($parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$current = $this->getCurrent();
|
||||||
$current = $this->getCurrent();
|
|
||||||
|
|
||||||
if ($current === true) {
|
if ($current === true) {
|
||||||
$search->filterById($this->request->get("folder_id"));
|
$search->filterById($this->request->get("folder_id"));
|
||||||
@@ -98,7 +96,6 @@ class Folder extends BaseLoop
|
|||||||
$search->filterById($this->request->get("folder_id"), Criteria::NOT_IN);
|
$search->filterById($this->request->get("folder_id"), Criteria::NOT_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$exclude = $this->getExclude();
|
$exclude = $this->getExclude();
|
||||||
|
|
||||||
if (!is_null($exclude)) {
|
if (!is_null($exclude)) {
|
||||||
@@ -111,7 +108,7 @@ class Folder extends BaseLoop
|
|||||||
|
|
||||||
$orders = $this->getOrder();
|
$orders = $this->getOrder();
|
||||||
|
|
||||||
foreach($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
switch ($order) {
|
switch ($order) {
|
||||||
case "alpha":
|
case "alpha":
|
||||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FolderI18nTableMap::TITLE);
|
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FolderI18nTableMap::TITLE);
|
||||||
@@ -157,26 +154,26 @@ class Folder extends BaseLoop
|
|||||||
$loopResultRow = new LoopResultRow();
|
$loopResultRow = new LoopResultRow();
|
||||||
|
|
||||||
$loopResultRow
|
$loopResultRow
|
||||||
->set("ID", $folder->getId())
|
->set("ID", $folder->getId())
|
||||||
->set("TITLE",$folder->getTitle())
|
->set("TITLE",$folder->getTitle())
|
||||||
->set("CHAPO", $folder->getChapo())
|
->set("CHAPO", $folder->getChapo())
|
||||||
->set("DESCRIPTION", $folder->getDescription())
|
->set("DESCRIPTION", $folder->getDescription())
|
||||||
->set("POSTSCRIPTUM", $folder->getPostscriptum())
|
->set("POSTSCRIPTUM", $folder->getPostscriptum())
|
||||||
->set("PARENT", $folder->getParent())
|
->set("PARENT", $folder->getParent())
|
||||||
->set("CONTENT_COUNT", $folder->countChild())
|
->set("CONTENT_COUNT", $folder->countChild())
|
||||||
->set("VISIBLE", $folder->getVisible() ? "1" : "0")
|
->set("VISIBLE", $folder->getVisible() ? "1" : "0")
|
||||||
->set("POSITION", $folder->getPosition())
|
->set("POSITION", $folder->getPosition())
|
||||||
|
|
||||||
->set("CREATE_DATE", $folder->getCreatedAt())
|
->set("CREATE_DATE", $folder->getCreatedAt())
|
||||||
->set("UPDATE_DATE", $folder->getUpdatedAt())
|
->set("UPDATE_DATE", $folder->getUpdatedAt())
|
||||||
->set("VERSION", $folder->getVersion())
|
->set("VERSION", $folder->getVersion())
|
||||||
->set("VERSION_DATE", $folder->getVersionCreatedAt())
|
->set("VERSION_DATE", $folder->getVersionCreatedAt())
|
||||||
->set("VERSION_AUTHOR", $folder->getVersionCreatedBy())
|
->set("VERSION_AUTHOR", $folder->getVersionCreatedBy())
|
||||||
;
|
;
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
$loopResult->addRow($loopResultRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
|
|||||||
|
|
||||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||||
|
|
||||||
use Thelia\Type\TypeCollection;
|
|
||||||
use Thelia\Type;
|
|
||||||
use Thelia\Model\LangQuery;
|
use Thelia\Model\LangQuery;
|
||||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||||
|
|
||||||
@@ -66,20 +64,20 @@ class Lang extends BaseLoop
|
|||||||
*/
|
*/
|
||||||
public function exec(&$pagination)
|
public function exec(&$pagination)
|
||||||
{
|
{
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
$exclude = $this->getExclude();
|
$exclude = $this->getExclude();
|
||||||
$default_only = $this->getDefaultOnly();
|
$default_only = $this->getDefaultOnly();
|
||||||
|
|
||||||
$search = LangQuery::create();
|
$search = LangQuery::create();
|
||||||
|
|
||||||
if (! is_null($id))
|
if (! is_null($id))
|
||||||
$search->filterById($id);
|
$search->filterById($id);
|
||||||
|
|
||||||
if ($default_only)
|
if ($default_only)
|
||||||
$search->filterByByDefault(true);
|
$search->filterByByDefault(true);
|
||||||
|
|
||||||
if (! is_null($exclude)) {
|
if (! is_null($exclude)) {
|
||||||
$search->filterById($exclude, Criteria::NOT_IN);
|
$search->filterById($exclude, Criteria::NOT_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
$search->orderByPosition(Criteria::ASC);
|
$search->orderByPosition(Criteria::ASC);
|
||||||
@@ -90,25 +88,25 @@ class Lang extends BaseLoop
|
|||||||
|
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
|
|
||||||
$loopResultRow = new LoopResultRow();
|
$loopResultRow = new LoopResultRow();
|
||||||
|
|
||||||
$loopResultRow
|
$loopResultRow
|
||||||
->set("ID", $result->getId())
|
->set("ID", $result->getId())
|
||||||
->set("TITLE",$result->getTitle())
|
->set("TITLE",$result->getTitle())
|
||||||
->set("CODE", $result->getCode())
|
->set("CODE", $result->getCode())
|
||||||
->set("LOCALE", $result->getLocale())
|
->set("LOCALE", $result->getLocale())
|
||||||
->set("URL", $result->getUrl())
|
->set("URL", $result->getUrl())
|
||||||
->set("IS_DEFAULT", $result->getByDefault())
|
->set("IS_DEFAULT", $result->getByDefault())
|
||||||
->set("URL", $result->getUrl())
|
->set("URL", $result->getUrl())
|
||||||
->set("POSITION", $result->getPosition())
|
->set("POSITION", $result->getPosition())
|
||||||
|
|
||||||
->set("CREATE_DATE", $result->getCreatedAt())
|
->set("CREATE_DATE", $result->getCreatedAt())
|
||||||
->set("UPDATE_DATE", $result->getUpdatedAt())
|
->set("UPDATE_DATE", $result->getUpdatedAt())
|
||||||
;
|
;
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
$loopResult->addRow($loopResultRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,14 +25,10 @@ namespace Thelia\Core\Template\Loop;
|
|||||||
|
|
||||||
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\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\Type\TypeCollection;
|
|
||||||
use Thelia\Type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @package Thelia\Core\Template\Loop
|
* @package Thelia\Core\Template\Loop
|
||||||
@@ -53,7 +49,7 @@ class Order extends BaseLoop
|
|||||||
*/
|
*/
|
||||||
public function exec(&$pagination)
|
public function exec(&$pagination)
|
||||||
{
|
{
|
||||||
// TODO : a coder !
|
// TODO : a coder !
|
||||||
return new LoopResult();
|
return new LoopResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,14 +25,10 @@ namespace Thelia\Core\Template\Loop;
|
|||||||
|
|
||||||
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\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\Type\TypeCollection;
|
|
||||||
use Thelia\Type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @package Thelia\Core\Template\Loop
|
* @package Thelia\Core\Template\Loop
|
||||||
@@ -53,7 +49,7 @@ class OrderStatus extends BaseLoop
|
|||||||
*/
|
*/
|
||||||
public function exec(&$pagination)
|
public function exec(&$pagination)
|
||||||
{
|
{
|
||||||
// TODO : a coder !
|
// TODO : a coder !
|
||||||
return new LoopResult();
|
return new LoopResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,20 +24,14 @@
|
|||||||
namespace Thelia\Core\Template\Loop;
|
namespace Thelia\Core\Template\Loop;
|
||||||
|
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Propel\Runtime\ActiveQuery\Join;
|
|
||||||
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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\Base\FeatureProductQuery;
|
|
||||||
use Thelia\Model\CategoryQuery;
|
use Thelia\Model\CategoryQuery;
|
||||||
use Thelia\Model\FeatureAvQuery;
|
|
||||||
use Thelia\Model\FeatureQuery;
|
|
||||||
use Thelia\Model\Map\FeatureProductTableMap;
|
|
||||||
use Thelia\Model\Map\ProductTableMap;
|
use Thelia\Model\Map\ProductTableMap;
|
||||||
use Thelia\Model\ProductCategoryQuery;
|
use Thelia\Model\ProductCategoryQuery;
|
||||||
use Thelia\Model\ProductQuery;
|
use Thelia\Model\ProductQuery;
|
||||||
@@ -130,15 +124,15 @@ class Product extends BaseLoop
|
|||||||
$search->filterByRef($ref, Criteria::IN);
|
$search->filterByRef($ref, Criteria::IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
$category = $this->getCategory();
|
$category = $this->getCategory();
|
||||||
|
|
||||||
if (!is_null($category)) {
|
if (!is_null($category)) {
|
||||||
$categories = CategoryQuery::create()->filterById($category, Criteria::IN)->find();
|
$categories = CategoryQuery::create()->filterById($category, Criteria::IN)->find();
|
||||||
|
|
||||||
$depth = $this->getDepth();
|
$depth = $this->getDepth();
|
||||||
|
|
||||||
if(null !== $depth) {
|
if (null !== $depth) {
|
||||||
foreach(CategoryQuery::findAllChild($category, $depth) as $subCategory) {
|
foreach (CategoryQuery::findAllChild($category, $depth) as $subCategory) {
|
||||||
$categories->prepend($subCategory);
|
$categories->prepend($subCategory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,7 +147,7 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
if ($new === true) {
|
if ($new === true) {
|
||||||
$search->filterByNewness(1, Criteria::EQUAL);
|
$search->filterByNewness(1, Criteria::EQUAL);
|
||||||
} else if($new === false) {
|
} elseif ($new === false) {
|
||||||
$search->filterByNewness(0, Criteria::EQUAL);
|
$search->filterByNewness(0, Criteria::EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +155,7 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
if ($promo === true) {
|
if ($promo === true) {
|
||||||
$search->filterByPromo(1, Criteria::EQUAL);
|
$search->filterByPromo(1, Criteria::EQUAL);
|
||||||
} else if($promo === false) {
|
} elseif ($promo === false) {
|
||||||
$search->filterByNewness(0, Criteria::EQUAL);
|
$search->filterByNewness(0, Criteria::EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +167,7 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
$min_price = $this->getMin_price();*/
|
$min_price = $this->getMin_price();*/
|
||||||
|
|
||||||
//if(null !== $min_price) {
|
//if (null !== $min_price) {
|
||||||
/**
|
/**
|
||||||
* Following should work but does not :
|
* Following should work but does not :
|
||||||
*
|
*
|
||||||
@@ -190,7 +184,7 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
$max_price = $this->getMax_price();*/
|
$max_price = $this->getMax_price();*/
|
||||||
|
|
||||||
//if(null !== $max_price) {
|
//if (null !== $max_price) {
|
||||||
/**
|
/**
|
||||||
* Following should work but does not :
|
* Following should work but does not :
|
||||||
*
|
*
|
||||||
@@ -207,13 +201,13 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
/*$min_weight = $this->getMin_weight();
|
/*$min_weight = $this->getMin_weight();
|
||||||
|
|
||||||
if(null !== $min_weight) {
|
if (null !== $min_weight) {
|
||||||
$search->filterByWeight($min_weight, Criteria::GREATER_EQUAL);
|
$search->filterByWeight($min_weight, Criteria::GREATER_EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$max_weight = $this->getMax_weight();
|
$max_weight = $this->getMax_weight();
|
||||||
|
|
||||||
if(null !== $max_weight) {
|
if (null !== $max_weight) {
|
||||||
$search->filterByWeight($max_weight, Criteria::LESS_EQUAL);
|
$search->filterByWeight($max_weight, Criteria::LESS_EQUAL);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@@ -221,7 +215,7 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
if ($current === true) {
|
if ($current === true) {
|
||||||
$search->filterById($this->request->get("product_id"));
|
$search->filterById($this->request->get("product_id"));
|
||||||
} elseif($current === false) {
|
} elseif ($current === false) {
|
||||||
$search->filterById($this->request->get("product_id"), Criteria::NOT_IN);
|
$search->filterById($this->request->get("product_id"), Criteria::NOT_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +232,7 @@ class Product extends BaseLoop
|
|||||||
)->find(),
|
)->find(),
|
||||||
Criteria::IN
|
Criteria::IN
|
||||||
);
|
);
|
||||||
} elseif($current_category === false) {
|
} elseif ($current_category === false) {
|
||||||
$search->filterByCategory(
|
$search->filterByCategory(
|
||||||
CategoryQuery::create()->filterByProduct(
|
CategoryQuery::create()->filterByProduct(
|
||||||
ProductCategoryQuery::create()->filterByProductId(
|
ProductCategoryQuery::create()->filterByProductId(
|
||||||
@@ -257,7 +251,7 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
$orders = $this->getOrder();
|
$orders = $this->getOrder();
|
||||||
|
|
||||||
foreach($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
switch ($order) {
|
switch ($order) {
|
||||||
case "alpha":
|
case "alpha":
|
||||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\ProductI18nTableMap::TITLE);
|
$search->addAscendingOrderByColumn(\Thelia\Model\Map\ProductI18nTableMap::TITLE);
|
||||||
@@ -293,7 +287,7 @@ class Product extends BaseLoop
|
|||||||
case "given_id":
|
case "given_id":
|
||||||
if(null === $id)
|
if(null === $id)
|
||||||
throw new \InvalidArgumentException('Given_id order cannot be set without `id` argument');
|
throw new \InvalidArgumentException('Given_id order cannot be set without `id` argument');
|
||||||
foreach($id as $singleId) {
|
foreach ($id as $singleId) {
|
||||||
$givenIdMatched = 'given_id_matched_' . $singleId;
|
$givenIdMatched = 'given_id_matched_' . $singleId;
|
||||||
$search->withColumn(ProductTableMap::ID . "='$singleId'", $givenIdMatched);
|
$search->withColumn(ProductTableMap::ID . "='$singleId'", $givenIdMatched);
|
||||||
$search->orderBy($givenIdMatched, Criteria::DESC);
|
$search->orderBy($givenIdMatched, Criteria::DESC);
|
||||||
@@ -323,9 +317,9 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
$feature_available = $this->getFeature_available();
|
$feature_available = $this->getFeature_available();
|
||||||
|
|
||||||
if(null !== $feature_available) {
|
if (null !== $feature_available) {
|
||||||
foreach($feature_available as $feature => $feature_choice) {
|
foreach ($feature_available as $feature => $feature_choice) {
|
||||||
foreach($feature_choice['values'] as $feature_av) {
|
foreach ($feature_choice['values'] as $feature_av) {
|
||||||
$featureAlias = 'fa_' . $feature;
|
$featureAlias = 'fa_' . $feature;
|
||||||
if($feature_av != '*')
|
if($feature_av != '*')
|
||||||
$featureAlias .= '_' . $feature_av;
|
$featureAlias .= '_' . $feature_av;
|
||||||
@@ -337,7 +331,7 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
/* format for mysql */
|
/* format for mysql */
|
||||||
$sqlWhereString = $feature_choice['expression'];
|
$sqlWhereString = $feature_choice['expression'];
|
||||||
if($sqlWhereString == '*') {
|
if ($sqlWhereString == '*') {
|
||||||
$sqlWhereString = 'NOT ISNULL(`fa_' . $feature . '`.ID)';
|
$sqlWhereString = 'NOT ISNULL(`fa_' . $feature . '`.ID)';
|
||||||
} else {
|
} else {
|
||||||
$sqlWhereString = preg_replace('#([0-9]+)#', 'NOT ISNULL(`fa_' . $feature . '_' . '\1`.ID)', $sqlWhereString);
|
$sqlWhereString = preg_replace('#([0-9]+)#', 'NOT ISNULL(`fa_' . $feature . '_' . '\1`.ID)', $sqlWhereString);
|
||||||
@@ -351,9 +345,9 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
$feature_values = $this->getFeature_values();
|
$feature_values = $this->getFeature_values();
|
||||||
|
|
||||||
if(null !== $feature_values) {
|
if (null !== $feature_values) {
|
||||||
foreach($feature_values as $feature => $feature_choice) {
|
foreach ($feature_values as $feature => $feature_choice) {
|
||||||
foreach($feature_choice['values'] as $feature_value) {
|
foreach ($feature_choice['values'] as $feature_value) {
|
||||||
$featureAlias = 'fv_' . $feature;
|
$featureAlias = 'fv_' . $feature;
|
||||||
if($feature_value != '*')
|
if($feature_value != '*')
|
||||||
$featureAlias .= '_' . $feature_value;
|
$featureAlias .= '_' . $feature_value;
|
||||||
@@ -365,7 +359,7 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
/* format for mysql */
|
/* format for mysql */
|
||||||
$sqlWhereString = $feature_choice['expression'];
|
$sqlWhereString = $feature_choice['expression'];
|
||||||
if($sqlWhereString == '*') {
|
if ($sqlWhereString == '*') {
|
||||||
$sqlWhereString = 'NOT ISNULL(`fv_' . $feature . '`.ID)';
|
$sqlWhereString = 'NOT ISNULL(`fv_' . $feature . '`.ID)';
|
||||||
} else {
|
} else {
|
||||||
$sqlWhereString = preg_replace('#([a-zA-Z0-9_\-]+)#', 'NOT ISNULL(`fv_' . $feature . '_' . '\1`.ID)', $sqlWhereString);
|
$sqlWhereString = preg_replace('#([a-zA-Z0-9_\-]+)#', 'NOT ISNULL(`fv_' . $feature . '_' . '\1`.ID)', $sqlWhereString);
|
||||||
@@ -398,18 +392,18 @@ class Product extends BaseLoop
|
|||||||
$loopResultRow = new LoopResultRow();
|
$loopResultRow = new LoopResultRow();
|
||||||
|
|
||||||
$loopResultRow->set("ID", $product->getId())
|
$loopResultRow->set("ID", $product->getId())
|
||||||
->set("REF",$product->getRef())
|
->set("REF",$product->getRef())
|
||||||
->set("TITLE",$product->getTitle())
|
->set("TITLE",$product->getTitle())
|
||||||
->set("CHAPO", $product->getChapo())
|
->set("CHAPO", $product->getChapo())
|
||||||
->set("DESCRIPTION", $product->getDescription())
|
->set("DESCRIPTION", $product->getDescription())
|
||||||
->set("POSTSCRIPTUM", $product->getPostscriptum())
|
->set("POSTSCRIPTUM", $product->getPostscriptum())
|
||||||
//->set("PRICE", $product->getPrice())
|
//->set("PRICE", $product->getPrice())
|
||||||
//->set("PROMO_PRICE", $product->getPrice2())
|
//->set("PROMO_PRICE", $product->getPrice2())
|
||||||
//->set("WEIGHT", $product->getWeight())
|
//->set("WEIGHT", $product->getWeight())
|
||||||
//->set("PROMO", $product->getPromo())
|
//->set("PROMO", $product->getPromo())
|
||||||
//->set("NEW", $product->getNewness())
|
//->set("NEW", $product->getNewness())
|
||||||
->set("POSITION", $product->getPosition())
|
->set("POSITION", $product->getPosition())
|
||||||
;
|
;
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
$loopResult->addRow($loopResultRow);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,9 @@ 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\Log\Tlog;
|
|
||||||
|
|
||||||
use Thelia\Model\CustomerTitleQuery;
|
use Thelia\Model\CustomerTitleQuery;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
use Thelia\Type\TypeCollection;
|
|
||||||
use Thelia\Type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -67,7 +64,7 @@ class Title extends BaseLoop
|
|||||||
{
|
{
|
||||||
$search = CustomerTitleQuery::create();
|
$search = CustomerTitleQuery::create();
|
||||||
|
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
|
|
||||||
if (null !== $id) {
|
if (null !== $id) {
|
||||||
$search->filterById($id, Criteria::IN);
|
$search->filterById($id, Criteria::IN);
|
||||||
@@ -102,4 +99,4 @@ class Title extends BaseLoop
|
|||||||
|
|
||||||
return $loopResult;
|
return $loopResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,62 +35,62 @@ use Thelia\Form\BaseForm;
|
|||||||
*/
|
*/
|
||||||
class ParserContext implements \IteratorAggregate
|
class ParserContext implements \IteratorAggregate
|
||||||
{
|
{
|
||||||
private $store = array();
|
private $store = array();
|
||||||
|
|
||||||
public function __construct(Request $request) {
|
public function __construct(Request $request)
|
||||||
|
{
|
||||||
|
// Setup basic variables
|
||||||
|
$this
|
||||||
|
->set('BASE_URL' , ConfigQuery::read('base_url', '/'))
|
||||||
|
->set('INDEX_PAGE' , URL::getIndexPage())
|
||||||
|
->set('RETURN_TO_URL' , URL::absoluteUrl($request->getSession()->getReturnToUrl()))
|
||||||
|
->set('THELIA_VERSION' , ConfigQuery::read('thelia_version', 'undefined'))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
// Setup basic variables
|
// -- Error form -----------------------------------------------------------
|
||||||
$this
|
|
||||||
->set('BASE_URL' , ConfigQuery::read('base_url', '/'))
|
|
||||||
->set('INDEX_PAGE' , URL::getIndexPage())
|
|
||||||
->set('RETURN_TO_URL' , URL::absoluteUrl($request->getSession()->getReturnToUrl()))
|
|
||||||
->set('THELIA_VERSION' , ConfigQuery::read('thelia_version', 'undefined'))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -- Error form -----------------------------------------------------------
|
/**
|
||||||
|
* @param BaseForm $form the errored form
|
||||||
|
*/
|
||||||
|
public function setErrorForm(BaseForm $form)
|
||||||
|
{
|
||||||
|
$this->set('error_form', $form);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public function getErrorForm()
|
||||||
* @param BaseForm $form the errored form
|
{
|
||||||
*/
|
return $this->get('error_form', null);
|
||||||
public function setErrorForm(BaseForm $form)
|
}
|
||||||
{
|
|
||||||
$this->set('error_form', $form);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getErrorForm()
|
public function clearErrorForm()
|
||||||
{
|
{
|
||||||
return $this->get('error_form', null);
|
return $this->remove('error_form');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clearErrorForm()
|
// -- Internal table manipulation ------------------------------------------
|
||||||
{
|
|
||||||
return $this->remove('error_form');
|
|
||||||
}
|
|
||||||
|
|
||||||
// -- Internal table manipulation ------------------------------------------
|
public function set($name, $value)
|
||||||
|
{
|
||||||
|
$this->store[$name] = $value;
|
||||||
|
|
||||||
public function set($name, $value)
|
return $this;
|
||||||
{
|
}
|
||||||
$this->store[$name] = $value;
|
|
||||||
|
|
||||||
return $this;
|
public function remove($name)
|
||||||
}
|
{
|
||||||
|
unset($this->store[$name]);
|
||||||
|
|
||||||
public function remove($name)
|
return $this;
|
||||||
{
|
}
|
||||||
unset($this->store[$name]);
|
|
||||||
|
|
||||||
return $this;
|
public function get($name, $default = null)
|
||||||
}
|
{
|
||||||
|
return isset($this->store[$name]) ? $this->store[$name] : $default;
|
||||||
|
}
|
||||||
|
|
||||||
public function get($name, $default = null)
|
public function getIterator()
|
||||||
{
|
{
|
||||||
return isset($this->store[$name]) ? $this->store[$name] : $default;
|
return new \ArrayIterator( $this->store );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIterator()
|
|
||||||
{
|
|
||||||
return new \ArrayIterator( $this->store );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,69 +32,67 @@ namespace Thelia\Core\Template\Smarty;
|
|||||||
*/
|
*/
|
||||||
abstract class AbstractSmartyPlugin
|
abstract class AbstractSmartyPlugin
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Explode a comma separated list in a array, trimming all array elements
|
* Explode a comma separated list in a array, trimming all array elements
|
||||||
*
|
*
|
||||||
* @param unknown $commaSeparatedValues
|
* @param unknown $commaSeparatedValues
|
||||||
* @return multitype:
|
* @return multitype:
|
||||||
*/
|
*/
|
||||||
protected function _explode($commaSeparatedValues)
|
protected function _explode($commaSeparatedValues)
|
||||||
{
|
{
|
||||||
$array = explode(',', $commaSeparatedValues);
|
$array = explode(',', $commaSeparatedValues);
|
||||||
|
|
||||||
if (array_walk($array, function(&$item) {
|
if (array_walk($array, function(&$item) {
|
||||||
$item = strtoupper(trim($item));
|
$item = strtoupper(trim($item));
|
||||||
})) {
|
})) {
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a function or block parameter value, and normalize it, trimming balnks and
|
* Get a function or block parameter value, and normalize it, trimming balnks and
|
||||||
* making it lowercase
|
* making it lowercase
|
||||||
*
|
*
|
||||||
* @param array $params the parameters array
|
* @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 $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)
|
* @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.
|
* @return mixed the parameter value, or the default value if it is not found.
|
||||||
*/
|
*/
|
||||||
public function getNormalizedParam($params, $name, $default = null)
|
public function getNormalizedParam($params, $name, $default = null)
|
||||||
{
|
{
|
||||||
$value = $this->getParam($params, $name, $default);
|
$value = $this->getParam($params, $name, $default);
|
||||||
|
|
||||||
if (is_string($value)) $value = strtolower(trim($value));
|
if (is_string($value)) $value = strtolower(trim($value));
|
||||||
|
return $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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif (isset($params[$name])) {
|
||||||
|
return $params[$name];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
return $default;
|
||||||
* 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
|
* @return an array of SmartyPluginDescriptor
|
||||||
*/
|
*/
|
||||||
public abstract function getPluginDescriptors();
|
abstract public function getPluginDescriptors();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
namespace Thelia\Core\Template\Smarty\Assets;
|
namespace Thelia\Core\Template\Smarty\Assets;
|
||||||
|
|
||||||
use Thelia\Core\Template\Assets\AsseticHelper;
|
use Thelia\Core\Template\Assets\AsseticHelper;
|
||||||
use Thelia\Model\ConfigQuery;
|
|
||||||
use Thelia\Tools\URL;
|
use Thelia\Tools\URL;
|
||||||
|
|
||||||
class SmartyAssetsManager
|
class SmartyAssetsManager
|
||||||
@@ -50,7 +49,8 @@ class SmartyAssetsManager
|
|||||||
$this->assetic_manager = new AsseticHelper();
|
$this->assetic_manager = new AsseticHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function computeAssetUrl($assetType, $params, \Smarty_Internal_Template $template) {
|
public function computeAssetUrl($assetType, $params, \Smarty_Internal_Template $template)
|
||||||
|
{
|
||||||
$file = $params['file'];
|
$file = $params['file'];
|
||||||
$filters = isset($params['filters']) ? $params['filters'] : '';
|
$filters = isset($params['filters']) ? $params['filters'] : '';
|
||||||
$debug = isset($params['debug']) ? trim(strtolower($params['debug'])) == 'true' : false;
|
$debug = isset($params['debug']) ? trim(strtolower($params['debug'])) == 'true' : false;
|
||||||
@@ -83,7 +83,7 @@ class SmartyAssetsManager
|
|||||||
{
|
{
|
||||||
// Opening tag (first call only)
|
// Opening tag (first call only)
|
||||||
if ($repeat) {
|
if ($repeat) {
|
||||||
$url = $this->computeAssetUrl($assetType, $params, $template);
|
$url = $this->computeAssetUrl($assetType, $params, $template);
|
||||||
|
|
||||||
$template->assign('asset_url', $url);
|
$template->assign('asset_url', $url);
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class Assetic extends AbstractSmartyPlugin
|
|||||||
|
|
||||||
public function functionImage($params, \Smarty_Internal_Template $template)
|
public function functionImage($params, \Smarty_Internal_Template $template)
|
||||||
{
|
{
|
||||||
return $this->assetManager->computeAssetUrl(SmartyAssetsManager::ASSET_TYPE_AUTO, $params, $template);
|
return $this->assetManager->computeAssetUrl(SmartyAssetsManager::ASSET_TYPE_AUTO, $params, $template);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -35,24 +35,24 @@ use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
|||||||
*/
|
*/
|
||||||
class DataAccessFunctions extends AbstractSmartyPlugin
|
class DataAccessFunctions extends AbstractSmartyPlugin
|
||||||
{
|
{
|
||||||
private $securityContext;
|
private $securityContext;
|
||||||
protected $parserContext;
|
protected $parserContext;
|
||||||
|
|
||||||
public function __construct(SecurityContext $securityContext, ParserContext $parserContext)
|
public function __construct(SecurityContext $securityContext, ParserContext $parserContext)
|
||||||
{
|
{
|
||||||
$this->securityContext = $securityContext;
|
$this->securityContext = $securityContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides access to the current logged administrator attributes using the accessors.
|
* Provides access to the current logged administrator attributes using the accessors.
|
||||||
*
|
*
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @param unknown $smarty
|
* @param unknown $smarty
|
||||||
* @return string the value of the requested attribute
|
* @return string the value of the requested attribute
|
||||||
*/
|
*/
|
||||||
public function adminDataAccess($params, &$smarty)
|
public function adminDataAccess($params, &$smarty)
|
||||||
{
|
{
|
||||||
return $this->userDataAccess("Admin User", SecurityContext::CONTEXT_BACK_OFFICE, $params);
|
return $this->userDataAccess("Admin User", SecurityContext::CONTEXT_BACK_OFFICE, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,38 +64,37 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
|||||||
*/
|
*/
|
||||||
public function customerDataAccess($params, &$smarty)
|
public function customerDataAccess($params, &$smarty)
|
||||||
{
|
{
|
||||||
return $this->userDataAccess("Customer User", SecurityContext::CONTEXT_FRONT_OFFICE, $params);
|
return $this->userDataAccess("Customer User", SecurityContext::CONTEXT_FRONT_OFFICE, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides access to user attributes using the accessors.
|
* Provides access to user attributes using the accessors.
|
||||||
*
|
*
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @param unknown $smarty
|
* @param unknown $smarty
|
||||||
* @return string the value of the requested attribute
|
* @return string the value of the requested attribute
|
||||||
* @throws InvalidArgumentException if the object does not have the requested attribute.
|
* @throws InvalidArgumentException if the object does not have the requested attribute.
|
||||||
*/
|
*/
|
||||||
protected function userDataAccess($objectLabel, $context, $params)
|
protected function userDataAccess($objectLabel, $context, $params)
|
||||||
{
|
{
|
||||||
$attribute = $this->getNormalizedParam($params, array('attribute', 'attrib', 'attr'));
|
$attribute = $this->getNormalizedParam($params, array('attribute', 'attrib', 'attr'));
|
||||||
|
|
||||||
if (! empty($attribute)) {
|
if (! empty($attribute)) {
|
||||||
$user = $this->securityContext->setContext($context)->getUser();
|
$user = $this->securityContext->setContext($context)->getUser();
|
||||||
|
|
||||||
if (null != $user) {
|
if (null != $user) {
|
||||||
$getter = sprintf("get%s", ucfirst($attribute));
|
$getter = sprintf("get%s", ucfirst($attribute));
|
||||||
|
|
||||||
if (method_exists($user, $getter)) {
|
if (method_exists($user, $getter)) {
|
||||||
return $user->$getter();
|
return $user->$getter();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException(sprintf("%s has no '%s' attribute", $objectLabel, $attribute));
|
throw new \InvalidArgumentException(sprintf("%s has no '%s' attribute", $objectLabel, $attribute));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Define the various smarty plugins hendled by this class
|
* Define the various smarty plugins hendled by this class
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ use Thelia\Core\Template\Element\Exception\ElementNotFoundException;
|
|||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||||
use Thelia\Log\Tlog;
|
|
||||||
use Thelia\Core\Template\ParserContext;
|
use Thelia\Core\Template\ParserContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,7 +84,7 @@ class Form extends AbstractSmartyPlugin
|
|||||||
{
|
{
|
||||||
if ($repeat) {
|
if ($repeat) {
|
||||||
|
|
||||||
$name = $this->getParam($params, 'name');
|
$name = $this->getParam($params, 'name');
|
||||||
|
|
||||||
if (null == $name) {
|
if (null == $name) {
|
||||||
throw new \InvalidArgumentException("Missing 'name' parameter in form arguments");
|
throw new \InvalidArgumentException("Missing 'name' parameter in form arguments");
|
||||||
@@ -98,11 +97,11 @@ class Form extends AbstractSmartyPlugin
|
|||||||
|
|
||||||
if (null != $errorForm && $errorForm->getName() == $instance->getName()) {
|
if (null != $errorForm && $errorForm->getName() == $instance->getName()) {
|
||||||
|
|
||||||
// Re-use the errored form
|
// Re-use the errored form
|
||||||
$instance = $errorForm;
|
$instance = $errorForm;
|
||||||
|
|
||||||
// Don't do that, as we may want to use this form firther in the template code
|
// Don't do that, as we may want to use this form firther in the template code
|
||||||
//$this->parserContext->clearErrorForm();
|
//$this->parserContext->clearErrorForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
$instance->createView();
|
$instance->createView();
|
||||||
@@ -111,8 +110,7 @@ class Form extends AbstractSmartyPlugin
|
|||||||
|
|
||||||
$template->assign("form_error", $instance->hasError() ? true : false);
|
$template->assign("form_error", $instance->hasError() ? true : false);
|
||||||
$template->assign("form_error_message", $instance->getErrorMessage());
|
$template->assign("form_error_message", $instance->getErrorMessage());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,7 +119,7 @@ class Form extends AbstractSmartyPlugin
|
|||||||
{
|
{
|
||||||
if ($repeat) {
|
if ($repeat) {
|
||||||
|
|
||||||
$formFieldView = $this->getFormFieldView($params);
|
$formFieldView = $this->getFormFieldView($params);
|
||||||
|
|
||||||
$template->assign("options", $formFieldView->vars);
|
$template->assign("options", $formFieldView->vars);
|
||||||
$template->assign("name", $formFieldView->vars["full_name"]);
|
$template->assign("name", $formFieldView->vars["full_name"]);
|
||||||
@@ -133,7 +131,7 @@ class Form extends AbstractSmartyPlugin
|
|||||||
$template->assign("error", empty($errors) ? false : true);
|
$template->assign("error", empty($errors) ? false : true);
|
||||||
|
|
||||||
if (! empty($errors)) {
|
if (! empty($errors)) {
|
||||||
$this->assignFieldErrorVars($template, $errors);
|
$this->assignFieldErrorVars($template, $errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
$attr = array();
|
$attr = array();
|
||||||
@@ -145,8 +143,7 @@ class Form extends AbstractSmartyPlugin
|
|||||||
$template->assign("attr", implode(" ", $attr));
|
$template->assign("attr", implode(" ", $attr));
|
||||||
|
|
||||||
$formFieldView->setRendered();
|
$formFieldView->setRendered();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,7 +152,7 @@ class Form extends AbstractSmartyPlugin
|
|||||||
{
|
{
|
||||||
$field = '<input type="hidden" name="%s" value="%s">';
|
$field = '<input type="hidden" name="%s" value="%s">';
|
||||||
|
|
||||||
$instance = $this->getInstanceFromParams($params);
|
$instance = $this->getInstanceFromParams($params);
|
||||||
|
|
||||||
$formView = $instance->getView();
|
$formView = $instance->getView();
|
||||||
|
|
||||||
@@ -172,7 +169,7 @@ class Form extends AbstractSmartyPlugin
|
|||||||
|
|
||||||
public function formEnctype($params, \Smarty_Internal_Template $template)
|
public function formEnctype($params, \Smarty_Internal_Template $template)
|
||||||
{
|
{
|
||||||
$instance = $this->getInstanceFromParams($params);
|
$instance = $this->getInstanceFromParams($params);
|
||||||
|
|
||||||
$formView = $instance->getForm();
|
$formView = $instance->getForm();
|
||||||
|
|
||||||
@@ -183,18 +180,17 @@ class Form extends AbstractSmartyPlugin
|
|||||||
|
|
||||||
public function formError($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
public function formError($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||||
{
|
{
|
||||||
$formFieldView = $this->getFormFieldView($params);
|
$formFieldView = $this->getFormFieldView($params);
|
||||||
|
|
||||||
$errors = $formFieldView->vars["errors"];
|
$errors = $formFieldView->vars["errors"];
|
||||||
|
|
||||||
if (empty($errors)) {
|
if (empty($errors)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($repeat) {
|
if ($repeat) {
|
||||||
$this->assignFieldErrorVars($template, $errors);
|
$this->assignFieldErrorVars($template, $errors);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,45 +198,46 @@ class Form extends AbstractSmartyPlugin
|
|||||||
|
|
||||||
protected function assignFieldErrorVars(\Smarty_Internal_Template $template, array $errors)
|
protected function assignFieldErrorVars(\Smarty_Internal_Template $template, array $errors)
|
||||||
{
|
{
|
||||||
$template->assign("message", $errors[0]->getMessage());
|
$template->assign("message", $errors[0]->getMessage());
|
||||||
$template->assign("parameters", $errors[0]->getMessageParameters());
|
$template->assign("parameters", $errors[0]->getMessageParameters());
|
||||||
$template->assign("pluralization", $errors[0]->getMessagePluralization());
|
$template->assign("pluralization", $errors[0]->getMessagePluralization());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isHidden(FormView $formView)
|
protected function isHidden(FormView $formView)
|
||||||
{
|
{
|
||||||
return array_search("hidden", $formView->vars["block_prefixes"]);
|
return array_search("hidden", $formView->vars["block_prefixes"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getFormFieldView($params) {
|
protected function getFormFieldView($params)
|
||||||
$instance = $this->getInstanceFromParams($params);
|
{
|
||||||
|
$instance = $this->getInstanceFromParams($params);
|
||||||
|
|
||||||
$fieldName = $this->getParam($params, 'field');
|
$fieldName = $this->getParam($params, 'field');
|
||||||
|
|
||||||
if (null == $fieldName)
|
if (null == $fieldName)
|
||||||
throw new \InvalidArgumentException("'field' parameter is missing");
|
throw new \InvalidArgumentException("'field' parameter is missing");
|
||||||
|
|
||||||
|
|
||||||
if (empty($instance->getView()[$fieldName]))
|
if (empty($instance->getView()[$fieldName]))
|
||||||
throw new \InvalidArgumentException(sprintf("Field name '%s' not found in form %s", $fieldName, $instance->getName()));
|
throw new \InvalidArgumentException(sprintf("Field name '%s' not found in form %s", $fieldName, $instance->getName()));
|
||||||
|
|
||||||
return $instance->getView()[$fieldName];
|
return $instance->getView()[$fieldName];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getInstanceFromParams($params) {
|
protected function getInstanceFromParams($params)
|
||||||
|
{
|
||||||
|
$instance = $this->getParam($params, 'form');
|
||||||
|
|
||||||
$instance = $this->getParam($params, 'form');
|
if (null == $instance) {
|
||||||
|
throw new \InvalidArgumentException("Missing 'form' parameter in form arguments");
|
||||||
|
}
|
||||||
|
|
||||||
if (null == $instance) {
|
if (! $instance instanceof \Thelia\Form\BaseForm) {
|
||||||
throw new \InvalidArgumentException("Missing 'form' parameter in form arguments");
|
throw new \InvalidArgumentException(sprintf("form parameter in form_field block must be an instance of
|
||||||
}
|
|
||||||
|
|
||||||
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)));
|
\Thelia\Form\BaseForm, instance of %s found", get_class($instance)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $instance;
|
return $instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createInstance($name)
|
protected function createInstance($name)
|
||||||
|
|||||||
@@ -25,54 +25,53 @@ namespace Thelia\Core\Template\Smarty\Plugins;
|
|||||||
|
|
||||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||||
use Thelia\Core\Template\Smarty\Assets\SmartyAssetsManager;
|
|
||||||
use Thelia\Core\Security\SecurityContext;
|
use Thelia\Core\Security\SecurityContext;
|
||||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||||
|
|
||||||
class Security extends AbstractSmartyPlugin
|
class Security extends AbstractSmartyPlugin
|
||||||
{
|
{
|
||||||
private $securityContext;
|
private $securityContext;
|
||||||
|
|
||||||
public function __construct(SecurityContext $securityContext)
|
public function __construct(SecurityContext $securityContext)
|
||||||
{
|
{
|
||||||
$this->securityContext = $securityContext;
|
$this->securityContext = $securityContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process security check function
|
* Process security check function
|
||||||
*
|
*
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @param unknown $smarty
|
* @param unknown $smarty
|
||||||
* @return string no text is returned.
|
* @return string no text is returned.
|
||||||
*/
|
*/
|
||||||
public function checkAuthFunction($params, &$smarty)
|
public function checkAuthFunction($params, &$smarty)
|
||||||
{
|
{
|
||||||
// Context: 'front' or 'admin'
|
// Context: 'front' or 'admin'
|
||||||
$context = $this->getNormalizedParam($params, 'context');
|
$context = $this->getNormalizedParam($params, 'context');
|
||||||
|
|
||||||
$this->securityContext->setContext($context);
|
$this->securityContext->setContext($context);
|
||||||
|
|
||||||
$roles = $this->_explode($this->getParam($params, 'roles'));
|
$roles = $this->_explode($this->getParam($params, 'roles'));
|
||||||
$permissions = $this->_explode($this->getParam($params, 'permissions'));
|
$permissions = $this->_explode($this->getParam($params, 'permissions'));
|
||||||
|
|
||||||
if (! $this->securityContext->isGranted($roles, $permissions)) {
|
if (! $this->securityContext->isGranted($roles, $permissions)) {
|
||||||
|
|
||||||
$ex = new AuthenticationException(
|
$ex = new AuthenticationException(
|
||||||
sprintf("User not granted for roles '%s', permissions '%s' in context '%s'.",
|
sprintf("User not granted for roles '%s', permissions '%s' in context '%s'.",
|
||||||
implode(',', $roles), implode(',', $permissions), $context
|
implode(',', $roles), implode(',', $permissions), $context
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$loginTpl = $this->getParam($params, 'login_tpl');
|
$loginTpl = $this->getParam($params, 'login_tpl');
|
||||||
|
|
||||||
if (null != $loginTpl) {
|
if (null != $loginTpl) {
|
||||||
$ex->setLoginTemplate($loginTpl);
|
$ex->setLoginTemplate($loginTpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw $ex;
|
throw $ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
*/
|
*/
|
||||||
public static function getPagination($loopId)
|
public static function getPagination($loopId)
|
||||||
{
|
{
|
||||||
if(!empty(self::$pagination[$loopId])) {
|
if (!empty(self::$pagination[$loopId])) {
|
||||||
return self::$pagination[$loopId];
|
return self::$pagination[$loopId];
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@@ -73,18 +73,18 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
*/
|
*/
|
||||||
public function theliaCount($params, $template)
|
public function theliaCount($params, $template)
|
||||||
{
|
{
|
||||||
$type = $this->getParam($params, 'type');
|
$type = $this->getParam($params, 'type');
|
||||||
|
|
||||||
if (null == $type)
|
if (null == $type)
|
||||||
throw new \InvalidArgumentException("Missing 'type' parameter in count arguments");
|
throw new \InvalidArgumentException("Missing 'type' parameter in count arguments");
|
||||||
|
|
||||||
$loop = $this->createLoopInstance($params);
|
$loop = $this->createLoopInstance($params);
|
||||||
|
|
||||||
$dummy = null;
|
$dummy = null;
|
||||||
|
|
||||||
$loopResults = $loop->exec($dummy);
|
$loopResults = $loop->exec($dummy);
|
||||||
|
|
||||||
return $loopResults->valid() ? $loopResults->getCount() : 0;
|
return $loopResults->valid() ? $loopResults->getCount() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +99,7 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
*/
|
*/
|
||||||
public function theliaLoop($params, $content, $template, &$repeat)
|
public function theliaLoop($params, $content, $template, &$repeat)
|
||||||
{
|
{
|
||||||
$name = $this->getParam($params, 'name');
|
$name = $this->getParam($params, 'name');
|
||||||
|
|
||||||
if (null == $name)
|
if (null == $name)
|
||||||
throw new \InvalidArgumentException("Missing 'name' parameter in loop arguments");
|
throw new \InvalidArgumentException("Missing 'name' parameter in loop arguments");
|
||||||
@@ -112,14 +112,14 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
if ($content === null) {
|
if ($content === null) {
|
||||||
// Check if a loop with the same name exists in the current scope, and abort if it's the case.
|
// Check if a loop with the same name exists in the current scope, and abort if it's the case.
|
||||||
if (array_key_exists($name, $this->varstack)) {
|
if (array_key_exists($name, $this->varstack)) {
|
||||||
throw new \InvalidArgumentException("A loop named '$name' already exists in the current scope.");
|
throw new \InvalidArgumentException("A loop named '$name' already exists in the current scope.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$loop = $this->createLoopInstance($params);
|
$loop = $this->createLoopInstance($params);
|
||||||
|
|
||||||
self::$pagination[$name] = null;
|
self::$pagination[$name] = null;
|
||||||
|
|
||||||
$loopResults = $loop->exec(self::$pagination[$name]);
|
$loopResults = $loop->exec(self::$pagination[$name]);
|
||||||
|
|
||||||
$this->loopstack[$name] = $loopResults;
|
$this->loopstack[$name] = $loopResults;
|
||||||
|
|
||||||
@@ -144,35 +144,35 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
$varlist[] = 'LOOP_COUNT';
|
$varlist[] = 'LOOP_COUNT';
|
||||||
$varlist[] = 'LOOP_TOTAL';
|
$varlist[] = 'LOOP_TOTAL';
|
||||||
|
|
||||||
foreach($varlist as $var) {
|
foreach ($varlist as $var) {
|
||||||
$saved_vars[$var] = $template->getTemplateVars($var);
|
$saved_vars[$var] = $template->getTemplateVars($var);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->varstack[$name] = $saved_vars;
|
$this->varstack[$name] = $saved_vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($loopResultRow->getVarVal() as $var => $val) {
|
foreach ($loopResultRow->getVarVal() as $var => $val) {
|
||||||
$template->assign($var, $val);
|
$template->assign($var, $val);
|
||||||
}
|
}
|
||||||
|
|
||||||
$repeat = true;
|
$repeat = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign meta information
|
// Assign meta information
|
||||||
$template->assign('LOOP_COUNT', 1 + $loopResults->key());
|
$template->assign('LOOP_COUNT', 1 + $loopResults->key());
|
||||||
$template->assign('LOOP_TOTAL', $loopResults->getCount());
|
$template->assign('LOOP_TOTAL', $loopResults->getCount());
|
||||||
|
|
||||||
// Loop is terminated. Cleanup.
|
// Loop is terminated. Cleanup.
|
||||||
if (! $repeat) {
|
if (! $repeat) {
|
||||||
// Restore previous variables values before terminating
|
// Restore previous variables values before terminating
|
||||||
if (isset($this->varstack[$name])) {
|
if (isset($this->varstack[$name])) {
|
||||||
foreach($this->varstack[$name] as $var => $value) {
|
foreach ($this->varstack[$name] as $var => $value) {
|
||||||
$template->assign($var, $value);
|
$template->assign($var, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($this->varstack[$name]);
|
unset($this->varstack[$name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($content !== null) {
|
if ($content !== null) {
|
||||||
if ($loopResults->isEmpty()) {
|
if ($loopResults->isEmpty()) {
|
||||||
@@ -195,10 +195,10 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
public function theliaElseloop($params, $content, $template, &$repeat)
|
public function theliaElseloop($params, $content, $template, &$repeat)
|
||||||
{
|
{
|
||||||
|
|
||||||
// When encoutering close tag, check if loop has results.
|
// When encoutering close tag, check if loop has results.
|
||||||
if ($repeat === false) {
|
if ($repeat === false) {
|
||||||
return $this->checkEmptyLoop($params, $template) ? $content : '';
|
return $this->checkEmptyLoop($params, $template) ? $content : '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -212,10 +212,10 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
*/
|
*/
|
||||||
public function theliaIfLoop($params, $content, $template, &$repeat)
|
public function theliaIfLoop($params, $content, $template, &$repeat)
|
||||||
{
|
{
|
||||||
// When encountering close tag, check if loop has results.
|
// When encountering close tag, check if loop has results.
|
||||||
if ($repeat === false) {
|
if ($repeat === false) {
|
||||||
return $this->checkEmptyLoop($params, $template) ? '' : $content;
|
return $this->checkEmptyLoop($params, $template) ? '' : $content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -231,7 +231,7 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
*/
|
*/
|
||||||
public function theliaPageLoop($params, $content, $template, &$repeat)
|
public function theliaPageLoop($params, $content, $template, &$repeat)
|
||||||
{
|
{
|
||||||
$loopName = $this->getParam($params, 'rel');
|
$loopName = $this->getParam($params, 'rel');
|
||||||
|
|
||||||
if (null == $loopName)
|
if (null == $loopName)
|
||||||
throw new \InvalidArgumentException("Missing 'rel' parameter in page loop");
|
throw new \InvalidArgumentException("Missing 'rel' parameter in page loop");
|
||||||
@@ -248,7 +248,7 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
throw new \InvalidArgumentException("Loop $loopName is not defined");
|
throw new \InvalidArgumentException("Loop $loopName is not defined");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($pagination->getNbResults() == 0) {
|
if ($pagination->getNbResults() == 0) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,10 +282,10 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
*/
|
*/
|
||||||
protected function checkEmptyLoop($params, $template)
|
protected function checkEmptyLoop($params, $template)
|
||||||
{
|
{
|
||||||
$loopName = $this->getParam($params, 'rel');
|
$loopName = $this->getParam($params, 'rel');
|
||||||
|
|
||||||
if (null == $loopName)
|
if (null == $loopName)
|
||||||
throw new \InvalidArgumentException("Missing 'rel' parameter in ifloop/elseloop arguments");
|
throw new \InvalidArgumentException("Missing 'rel' parameter in ifloop/elseloop arguments");
|
||||||
|
|
||||||
if (! isset($this->loopstack[$loopName])) {
|
if (! isset($this->loopstack[$loopName])) {
|
||||||
throw new \InvalidArgumentException("Loop $loopName is not defined.");
|
throw new \InvalidArgumentException("Loop $loopName is not defined.");
|
||||||
@@ -298,14 +298,14 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
*
|
*
|
||||||
* find the loop class with his name and construct an instance of this class
|
* find the loop class with his name and construct an instance of this class
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return \Thelia\Core\Template\Element\BaseLoop
|
* @return \Thelia\Core\Template\Element\BaseLoop
|
||||||
* @throws InvalidElementException
|
* @throws InvalidElementException
|
||||||
* @throws ElementNotFoundException
|
* @throws ElementNotFoundException
|
||||||
*/
|
*/
|
||||||
protected function createLoopInstance($smartyParams)
|
protected function createLoopInstance($smartyParams)
|
||||||
{
|
{
|
||||||
$type = strtolower($smartyParams['type']);
|
$type = strtolower($smartyParams['type']);
|
||||||
|
|
||||||
if (! isset($this->loopDefinition[$type])) {
|
if (! isset($this->loopDefinition[$type])) {
|
||||||
throw new ElementNotFoundException(sprintf("%s loop does not exists", $type));
|
throw new ElementNotFoundException(sprintf("%s loop does not exists", $type));
|
||||||
@@ -321,7 +321,7 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
$loop = $class->newInstance(
|
$loop = $class->newInstance(
|
||||||
$this->request,
|
$this->request,
|
||||||
$this->dispatcher,
|
$this->dispatcher,
|
||||||
$this->securityContext
|
$this->securityContext
|
||||||
);
|
);
|
||||||
|
|
||||||
$loop->initializeArgs($smartyParams);
|
$loop->initializeArgs($smartyParams);
|
||||||
@@ -367,11 +367,11 @@ class TheliaLoop extends AbstractSmartyPlugin
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
|
||||||
new SmartyPluginDescriptor('function', 'count' , $this, 'theliaCount'),
|
new SmartyPluginDescriptor('function', 'count' , $this, 'theliaCount'),
|
||||||
new SmartyPluginDescriptor('block' , 'loop' , $this, 'theliaLoop'),
|
new SmartyPluginDescriptor('block' , 'loop' , $this, 'theliaLoop'),
|
||||||
new SmartyPluginDescriptor('block' , 'elseloop' , $this, 'theliaElseloop'),
|
new SmartyPluginDescriptor('block' , 'elseloop' , $this, 'theliaElseloop'),
|
||||||
new SmartyPluginDescriptor('block' , 'ifloop' , $this, 'theliaIfLoop'),
|
new SmartyPluginDescriptor('block' , 'ifloop' , $this, 'theliaIfLoop'),
|
||||||
new SmartyPluginDescriptor('block' , 'pageloop' , $this, 'theliaPageLoop'),
|
new SmartyPluginDescriptor('block' , 'pageloop' , $this, 'theliaPageLoop'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class TheliaSyntax extends AbstractSmartyPlugin
|
|||||||
{
|
{
|
||||||
public function dieseCancel($value, $diese)
|
public function dieseCancel($value, $diese)
|
||||||
{
|
{
|
||||||
if($value === null) {
|
if ($value === null) {
|
||||||
return $diese;
|
return $diese;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,11 +29,12 @@ use Symfony\Component\Translation\TranslatorInterface;
|
|||||||
|
|
||||||
class Translation extends AbstractSmartyPlugin
|
class Translation extends AbstractSmartyPlugin
|
||||||
{
|
{
|
||||||
protected $translator;
|
protected $translator;
|
||||||
|
|
||||||
public function __construct(TranslatorInterface $translator) {
|
public function __construct(TranslatorInterface $translator)
|
||||||
$this->translator = $translator;
|
{
|
||||||
}
|
$this->translator = $translator;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process translate function
|
* Process translate function
|
||||||
@@ -44,15 +45,15 @@ class Translation extends AbstractSmartyPlugin
|
|||||||
*/
|
*/
|
||||||
public function translate($params, &$smarty)
|
public function translate($params, &$smarty)
|
||||||
{
|
{
|
||||||
// All parameters other than 'l' are supposed to be variables. Build an array of var => value pairs
|
// All parameters other than 'l' are supposed to be variables. Build an array of var => value pairs
|
||||||
// and pass it to the translator
|
// and pass it to the translator
|
||||||
$vars = array();
|
$vars = array();
|
||||||
|
|
||||||
foreach($params as $name => $value) {
|
foreach ($params as $name => $value) {
|
||||||
if ($name != 'l') $vars["%$name"] = $value;
|
if ($name != 'l') $vars["%$name"] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->translator->trans($this->getParam($params, 'l'), $vars);
|
return $this->translator->trans($this->getParam($params, 'l'), $vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,25 +37,24 @@ class UrlGenerator extends AbstractSmartyPlugin
|
|||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process url generator function
|
* Process url generator function
|
||||||
*
|
*
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @param unknown $smarty
|
* @param unknown $smarty
|
||||||
* @return string no text is returned.
|
* @return string no text is returned.
|
||||||
*/
|
*/
|
||||||
public function generateUrlFunction($params, &$smarty)
|
public function generateUrlFunction($params, &$smarty)
|
||||||
{
|
{
|
||||||
// the path to process
|
// the path to process
|
||||||
$path = $this->getParam($params, 'path');
|
$path = $this->getParam($params, 'path');
|
||||||
|
|
||||||
$target = $this->getParam($params, 'target', null);
|
$target = $this->getParam($params, 'target', null);
|
||||||
|
|
||||||
$url = URL::absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target')));
|
$url = URL::absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target')));
|
||||||
|
|
||||||
if ($target != null) $url .= '#'.$target;
|
if ($target != null) $url .= '#'.$target;
|
||||||
|
return $url;
|
||||||
return $url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +66,7 @@ class UrlGenerator extends AbstractSmartyPlugin
|
|||||||
*/
|
*/
|
||||||
public function generateFrontViewUrlFunction($params, &$smarty)
|
public function generateFrontViewUrlFunction($params, &$smarty)
|
||||||
{
|
{
|
||||||
return $this->generateViewUrlFunction($params, false);
|
return $this->generateViewUrlFunction($params, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,22 +78,21 @@ class UrlGenerator extends AbstractSmartyPlugin
|
|||||||
*/
|
*/
|
||||||
public function generateAdminViewUrlFunction($params, &$smarty)
|
public function generateAdminViewUrlFunction($params, &$smarty)
|
||||||
{
|
{
|
||||||
return $this->generateViewUrlFunction($params, true);
|
return $this->generateViewUrlFunction($params, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function generateViewUrlFunction($params, $forAdmin)
|
protected function generateViewUrlFunction($params, $forAdmin)
|
||||||
{
|
{
|
||||||
// the view name (without .html)
|
// the view name (without .html)
|
||||||
$view = $this->getParam($params,'view');
|
$view = $this->getParam($params,'view');
|
||||||
|
|
||||||
// the related action (optionale)
|
// the related action (optionale)
|
||||||
$action = $this->getParam($params, 'action');
|
$action = $this->getParam($params, 'action');
|
||||||
|
|
||||||
$args = $this->getArgsFromParam($params, array('view', 'action', 'target'));
|
$args = $this->getArgsFromParam($params, array('view', 'action', 'target'));
|
||||||
|
|
||||||
if (! empty($action)) $args['action'] = $action;
|
if (! empty($action)) $args['action'] = $action;
|
||||||
|
return $forAdmin ? URL::adminViewUrl($view, $args) : URL::viewUrl($view, $args);
|
||||||
return $forAdmin ? URL::adminViewUrl($view, $args) : URL::viewUrl($view, $args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,18 +101,18 @@ class UrlGenerator extends AbstractSmartyPlugin
|
|||||||
* @param array $params Smarty function params
|
* @param array $params Smarty function params
|
||||||
* @return array the parameters array (either emply, of valued)
|
* @return array the parameters array (either emply, of valued)
|
||||||
*/
|
*/
|
||||||
private function getArgsFromParam($params, $exclude = array()) {
|
private function getArgsFromParam($params, $exclude = array())
|
||||||
|
{
|
||||||
|
$pairs = array();
|
||||||
|
|
||||||
$pairs = array();
|
foreach ($params as $name => $value) {
|
||||||
|
|
||||||
foreach($params as $name => $value) {
|
if (in_array($name, $exclude)) continue;
|
||||||
|
|
||||||
if (in_array($name, $exclude)) continue;
|
$pairs[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
$pairs[$name] = $value;
|
return $pairs;
|
||||||
}
|
|
||||||
|
|
||||||
return $pairs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
* @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)
|
$template = false, $env = "prod", $debug = false)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
$this->error_reporting = E_ALL ^ E_NOTICE;
|
$this->error_reporting = E_ALL ^ E_NOTICE;
|
||||||
|
|
||||||
// Si on n'est pas en mode debug, activer le cache, avec une lifetime de 15mn, et en vérifiant que les templates sources n'ont pas été modifiés.
|
// Si on n'est pas en mode debug, activer le cache, avec une lifetime de 15mn, et en vérifiant que les templates sources n'ont pas été modifiés.
|
||||||
if($debug === false) {
|
if ($debug === false) {
|
||||||
$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
|
$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
|
||||||
$this->cache_lifetime = 300;
|
$this->cache_lifetime = 300;
|
||||||
$this->compile_check = true;
|
$this->compile_check = true;
|
||||||
@@ -87,15 +87,15 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
|
|
||||||
public function preThelia($tpl_source, \Smarty_Internal_Template $template)
|
public function preThelia($tpl_source, \Smarty_Internal_Template $template)
|
||||||
{
|
{
|
||||||
$new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9\-_]*)(.*)}`', '{\$$1$2}', $tpl_source);
|
$new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9\-_]*)(.*)}`', '{\$$1$2}', $tpl_source);
|
||||||
$new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9\-_]*)`', '{\$$1|dieseCanceller:\'#$1\'}', $new_source);
|
$new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9\-_]*)`', '{\$$1|dieseCanceller:\'#$1\'}', $new_source);
|
||||||
|
|
||||||
return $new_source;
|
return $new_source;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeBlankLines($tpl_source, \Smarty_Internal_Template $template)
|
public function removeBlankLines($tpl_source, \Smarty_Internal_Template $template)
|
||||||
{
|
{
|
||||||
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $tpl_source);
|
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $tpl_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTemplate($template_path_from_template_base)
|
public function setTemplate($template_path_from_template_base)
|
||||||
@@ -119,10 +119,10 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
*/
|
*/
|
||||||
public function render($realTemplateName, array $parameters = array())
|
public function render($realTemplateName, array $parameters = array())
|
||||||
{
|
{
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assign($parameters);
|
$this->assign($parameters);
|
||||||
|
|
||||||
@@ -138,8 +138,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$templateFile = $this->getTemplateFilePath();
|
$templateFile = $this->getTemplateFilePath();
|
||||||
}
|
} catch (\RuntimeException $e) {
|
||||||
catch(\RuntimeException $e) {
|
|
||||||
return new Response($e->getMessage(), "404");
|
return new Response($e->getMessage(), "404");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +218,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
if (!file_exists($fileName)) {
|
if (!file_exists($fileName)) {
|
||||||
$fileName .= ".html";
|
$fileName .= ".html";
|
||||||
|
|
||||||
if(!file_exists($fileName)) {
|
if (!file_exists($fileName)) {
|
||||||
throw new ResourceNotFoundException(sprintf("%s file not found in %s template", $file, $this->template));
|
throw new ResourceNotFoundException(sprintf("%s file not found in %s template", $file, $this->template));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ use Symfony\Component\Yaml\Yaml;
|
|||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
|
|
||||||
use Thelia\Core\Bundle;
|
use Thelia\Core\Bundle;
|
||||||
use Thelia\Core\DependencyInjection\Loader\CollectionXmlFileLoader;
|
|
||||||
use Thelia\Log\Tlog;
|
use Thelia\Log\Tlog;
|
||||||
use Thelia\Config\DatabaseConfiguration;
|
use Thelia\Config\DatabaseConfiguration;
|
||||||
use Thelia\Config\DefinePropel;
|
use Thelia\Config\DefinePropel;
|
||||||
|
|||||||
@@ -131,17 +131,17 @@ class TheliaHttpKernel extends HttpKernel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return null|\Thelia\Model\Lang
|
* @return null|\Thelia\Model\Lang
|
||||||
*/
|
*/
|
||||||
protected function detectLang(Request $request)
|
protected function detectLang(Request $request)
|
||||||
{
|
{
|
||||||
$lang = null;
|
$lang = null;
|
||||||
//first priority => lang parameter present in request (get or post)
|
//first priority => lang parameter present in request (get or post)
|
||||||
if($request->query->has("lang")) {
|
if ($request->query->has("lang")) {
|
||||||
$lang = Model\LangQuery::create()->findOneByCode($request->query->get("lang"));
|
$lang = Model\LangQuery::create()->findOneByCode($request->query->get("lang"));
|
||||||
|
|
||||||
if(is_null($lang)) {
|
if (is_null($lang)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,26 +3,26 @@ namespace Thelia\Core\Translation;
|
|||||||
|
|
||||||
use Symfony\Component\Translation\Translator as BaseTranslator;
|
use Symfony\Component\Translation\Translator as BaseTranslator;
|
||||||
|
|
||||||
class Translator extends BaseTranslator {
|
class Translator extends BaseTranslator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null)
|
||||||
|
{
|
||||||
|
if (null === $locale) {
|
||||||
|
$locale = $this->getLocale();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
if (!isset($this->catalogues[$locale])) {
|
||||||
* {@inheritdoc}
|
$this->loadCatalogue($locale);
|
||||||
*
|
}
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null)
|
|
||||||
{
|
|
||||||
if (null === $locale) {
|
|
||||||
$locale = $this->getLocale();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->catalogues[$locale])) {
|
if ($this->catalogues[$locale]->has((string) $id, $domain))
|
||||||
$this->loadCatalogue($locale);
|
return parent::trans($id, $parameters, $domain = 'messages', $locale = null);
|
||||||
}
|
else
|
||||||
|
return strtr($id, $parameters);
|
||||||
if ($this->catalogues[$locale]->has((string) $id, $domain))
|
}
|
||||||
return parent::trans($id, $parameters, $domain = 'messages', $locale = null);
|
}
|
||||||
else
|
|
||||||
return strtr($id, $parameters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -21,10 +21,8 @@
|
|||||||
/* */
|
/* */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
namespace Thelia\Exception;
|
namespace Thelia\Exception;
|
||||||
|
|
||||||
|
class InvalidCartException extends \RuntimeException
|
||||||
class InvalidCartException extends \RuntimeException {
|
{
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -22,13 +22,11 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Form;
|
namespace Thelia\Form;
|
||||||
|
|
||||||
|
|
||||||
use Symfony\Component\Validator\Constraints\Length;
|
use Symfony\Component\Validator\Constraints\Length;
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
use Symfony\Component\Validator\Constraints\Choice;
|
|
||||||
|
|
||||||
class AdminLogin extends BaseForm {
|
|
||||||
|
|
||||||
|
class AdminLogin extends BaseForm
|
||||||
|
{
|
||||||
protected function buildForm()
|
protected function buildForm()
|
||||||
{
|
{
|
||||||
$this->formBuilder
|
$this->formBuilder
|
||||||
@@ -40,11 +38,11 @@ class AdminLogin extends BaseForm {
|
|||||||
))
|
))
|
||||||
->add("password", "password", array(
|
->add("password", "password", array(
|
||||||
"constraints" => array(
|
"constraints" => array(
|
||||||
new NotBlank()
|
new NotBlank()
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
->add("remember_me", "checkbox", array(
|
->add("remember_me", "checkbox", array(
|
||||||
'value' => 'yes'
|
'value' => 'yes'
|
||||||
))
|
))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ namespace Thelia\Form;
|
|||||||
|
|
||||||
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
|
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
|
||||||
use Symfony\Component\Form\Forms;
|
use Symfony\Component\Form\Forms;
|
||||||
use Symfony\Component\HttpFoundation\Session\Session;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
|
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
|
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
|
||||||
@@ -33,7 +32,8 @@ use Symfony\Component\Validator\Validation;
|
|||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
use Thelia\Tools\URL;
|
use Thelia\Tools\URL;
|
||||||
|
|
||||||
abstract class BaseForm {
|
abstract class BaseForm
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Symfony\Component\Form\FormFactoryInterface
|
* @var \Symfony\Component\Form\FormFactoryInterface
|
||||||
*/
|
*/
|
||||||
@@ -46,33 +46,33 @@ abstract class BaseForm {
|
|||||||
|
|
||||||
protected $request;
|
protected $request;
|
||||||
|
|
||||||
private $view = null;
|
private $view = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true if the form has an error, false otherwise.
|
* true if the form has an error, false otherwise.
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
private $has_error = false;
|
private $has_error = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The form error message.
|
* The form error message.
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $error_message = '';
|
private $error_message = '';
|
||||||
|
|
||||||
public function __construct(Request $request, $type= "form", $data = array(), $options = array())
|
public function __construct(Request $request, $type= "form", $data = array(), $options = array())
|
||||||
{
|
{
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
|
||||||
$validator = Validation::createValidator();
|
$validator = Validation::createValidator();
|
||||||
|
|
||||||
if(!isset($options["attr"]["name"])) {
|
if (!isset($options["attr"]["name"])) {
|
||||||
$options["attr"]["thelia_name"] = $this->getName();
|
$options["attr"]["thelia_name"] = $this->getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
$builder = Forms::createFormFactoryBuilder()
|
$builder = Forms::createFormFactoryBuilder()
|
||||||
->addExtension(new HttpFoundationExtension());
|
->addExtension(new HttpFoundationExtension());
|
||||||
if(!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
|
if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
|
||||||
$builder->addExtension(
|
$builder->addExtension(
|
||||||
new CsrfExtension(
|
new CsrfExtension(
|
||||||
new SessionCsrfProvider(
|
new SessionCsrfProvider(
|
||||||
@@ -92,14 +92,15 @@ abstract class BaseForm {
|
|||||||
|
|
||||||
// If not already set, define the success_url field
|
// If not already set, define the success_url field
|
||||||
if (! $this->formBuilder->has('success_url')) {
|
if (! $this->formBuilder->has('success_url')) {
|
||||||
$this->formBuilder->add("success_url", "text");
|
$this->formBuilder->add("success_url", "text");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->form = $this->formBuilder->getForm();
|
$this->form = $this->formBuilder->getForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRequest() {
|
public function getRequest()
|
||||||
return $this->request;
|
{
|
||||||
|
return $this->request;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function cleanOptions($options)
|
protected function cleanOptions($options)
|
||||||
@@ -116,28 +117,29 @@ abstract class BaseForm {
|
|||||||
*
|
*
|
||||||
* @return string an absolute URL
|
* @return string an absolute URL
|
||||||
*/
|
*/
|
||||||
public function getSuccessUrl($default = null) {
|
public function getSuccessUrl($default = null)
|
||||||
|
{
|
||||||
|
$successUrl = $this->form->get('success_url')->getData();
|
||||||
|
|
||||||
$successUrl = $this->form->get('success_url')->getData();
|
if (empty($successUrl)) {
|
||||||
|
|
||||||
if (empty($successUrl)) {
|
if ($default === null) $default = ConfigQuery::read('base_url', '/');
|
||||||
|
|
||||||
if ($default === null) $default = ConfigQuery::read('base_url', '/');
|
$successUrl = $default;
|
||||||
|
}
|
||||||
|
|
||||||
$successUrl = $default;
|
return URL::absoluteUrl($successUrl);
|
||||||
}
|
|
||||||
|
|
||||||
return URL::absoluteUrl($successUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createView() {
|
public function createView()
|
||||||
$this->view = $this->form->createView();
|
{
|
||||||
|
$this->view = $this->form->createView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getView() {
|
public function getView()
|
||||||
if ($this->view === null) throw new \LogicException("View was not created. Please call BaseForm::createView() first.");
|
{
|
||||||
|
if ($this->view === null) throw new \LogicException("View was not created. Please call BaseForm::createView() first.");
|
||||||
return $this->view;
|
return $this->view;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- Error and errro message ----------------------------------------------
|
// -- Error and errro message ----------------------------------------------
|
||||||
@@ -149,7 +151,7 @@ abstract class BaseForm {
|
|||||||
*/
|
*/
|
||||||
public function setError($has_error = true)
|
public function setError($has_error = true)
|
||||||
{
|
{
|
||||||
$this->has_error = $has_error;
|
$this->has_error = $has_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,7 +161,7 @@ abstract class BaseForm {
|
|||||||
*/
|
*/
|
||||||
public function hasError()
|
public function hasError()
|
||||||
{
|
{
|
||||||
return $this->has_error;
|
return $this->has_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -169,7 +171,7 @@ abstract class BaseForm {
|
|||||||
*/
|
*/
|
||||||
public function setErrorMessage($message)
|
public function setErrorMessage($message)
|
||||||
{
|
{
|
||||||
$this->error_message = $message;
|
$this->error_message = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,7 +181,7 @@ abstract class BaseForm {
|
|||||||
*/
|
*/
|
||||||
public function getErrorMessage()
|
public function getErrorMessage()
|
||||||
{
|
{
|
||||||
return $this->error_message;
|
return $this->error_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -217,4 +219,3 @@ abstract class BaseForm {
|
|||||||
*/
|
*/
|
||||||
abstract public function getName();
|
abstract public function getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Form;
|
namespace Thelia\Form;
|
||||||
|
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
|
||||||
use Symfony\Component\Validator\Constraints;
|
use Symfony\Component\Validator\Constraints;
|
||||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||||
use Thelia\Action\Exception\StockNotFoundException;
|
use Thelia\Action\Exception\StockNotFoundException;
|
||||||
@@ -135,4 +134,4 @@ class CartAdd extends BaseForm
|
|||||||
{
|
{
|
||||||
return "thelia_cart_add";
|
return "thelia_cart_add";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,10 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Form;
|
namespace Thelia\Form;
|
||||||
|
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
|
|
||||||
class CategoryCreationForm extends BaseForm {
|
class CategoryCreationForm extends BaseForm
|
||||||
|
{
|
||||||
protected function buildForm()
|
protected function buildForm()
|
||||||
{
|
{
|
||||||
$this->formBuilder
|
$this->formBuilder
|
||||||
@@ -37,13 +36,13 @@ class CategoryCreationForm extends BaseForm {
|
|||||||
))
|
))
|
||||||
->add("parent", "integer", array(
|
->add("parent", "integer", array(
|
||||||
"constraints" => array(
|
"constraints" => array(
|
||||||
new NotBlank()
|
new NotBlank()
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
->add("locale", "text", array(
|
->add("locale", "text", array(
|
||||||
"constraints" => array(
|
"constraints" => array(
|
||||||
new NotBlank()
|
new NotBlank()
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,17 +22,16 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Form;
|
namespace Thelia\Form;
|
||||||
|
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
|
|
||||||
class CategoryDeletionForm extends BaseForm {
|
class CategoryDeletionForm extends BaseForm
|
||||||
|
{
|
||||||
protected function buildForm()
|
protected function buildForm()
|
||||||
{
|
{
|
||||||
$this->formBuilder
|
$this->formBuilder
|
||||||
->add("category_id", "integer", array(
|
->add("category_id", "integer", array(
|
||||||
"constraints" => array(
|
"constraints" => array(
|
||||||
new NotBlank()
|
new NotBlank()
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
;
|
;
|
||||||
@@ -42,4 +41,4 @@ class CategoryDeletionForm extends BaseForm {
|
|||||||
{
|
{
|
||||||
return "thelia_category_deletion";
|
return "thelia_category_deletion";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class CustomerCreation extends BaseForm
|
|||||||
{
|
{
|
||||||
$this->formBuilder
|
$this->formBuilder
|
||||||
->add("auto_login", "integer")
|
->add("auto_login", "integer")
|
||||||
->add("firstname", "text", array(
|
->add("firstname", "text", array(
|
||||||
"constraints" => array(
|
"constraints" => array(
|
||||||
new Constraints\NotBlank()
|
new Constraints\NotBlank()
|
||||||
),
|
),
|
||||||
@@ -163,4 +163,4 @@ class CustomerCreation extends BaseForm
|
|||||||
{
|
{
|
||||||
return "thelia_customer_creation";
|
return "thelia_customer_creation";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,15 +22,11 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Form;
|
namespace Thelia\Form;
|
||||||
|
|
||||||
|
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
|
||||||
use Symfony\Component\Validator\Constraints\Length;
|
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
use Symfony\Component\Validator\Constraints\Choice;
|
|
||||||
use Symfony\Component\Validator\Constraints\Email;
|
use Symfony\Component\Validator\Constraints\Email;
|
||||||
|
|
||||||
class CustomerLogin extends BaseForm {
|
class CustomerLogin extends BaseForm
|
||||||
|
{
|
||||||
protected function buildForm()
|
protected function buildForm()
|
||||||
{
|
{
|
||||||
$this->formBuilder
|
$this->formBuilder
|
||||||
@@ -42,7 +38,7 @@ class CustomerLogin extends BaseForm {
|
|||||||
))
|
))
|
||||||
->add("password", "password", array(
|
->add("password", "password", array(
|
||||||
"constraints" => array(
|
"constraints" => array(
|
||||||
new NotBlank()
|
new NotBlank()
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
->add("remember_me", "checkbox")
|
->add("remember_me", "checkbox")
|
||||||
|
|||||||
@@ -24,11 +24,9 @@
|
|||||||
namespace Thelia\Form;
|
namespace Thelia\Form;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Constraints;
|
use Symfony\Component\Validator\Constraints;
|
||||||
use Thelia\Model\Customer;
|
|
||||||
|
|
||||||
|
|
||||||
class CustomerModification extends BaseForm {
|
|
||||||
|
|
||||||
|
class CustomerModification extends BaseForm
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* in this function you add all the fields you need for your Form.
|
* in this function you add all the fields you need for your Form.
|
||||||
@@ -53,7 +51,7 @@ class CustomerModification extends BaseForm {
|
|||||||
{
|
{
|
||||||
|
|
||||||
$this->formBuilder
|
$this->formBuilder
|
||||||
->add('update_logged_in_user', 'boolean') // In a front office context, update the in-memory logged-in user data
|
->add('update_logged_in_user', 'boolean') // In a front office context, update the in-memory logged-in user data
|
||||||
->add("firstname", "text", array(
|
->add("firstname", "text", array(
|
||||||
"constraints" => array(
|
"constraints" => array(
|
||||||
new Constraints\NotBlank()
|
new Constraints\NotBlank()
|
||||||
@@ -118,4 +116,4 @@ class CustomerModification extends BaseForm {
|
|||||||
{
|
{
|
||||||
return "thelia_customer_modification";
|
return "thelia_customer_modification";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ abstract class AbstractTlogDestination
|
|||||||
{
|
{
|
||||||
$this->_configs = array();
|
$this->_configs = array();
|
||||||
$this->_logs = array();
|
$this->_logs = array();
|
||||||
|
|
||||||
// Initialiser les variables de configuration
|
// Initialiser les variables de configuration
|
||||||
$this->_configs = $this->getConfigs();
|
$this->_configs = $this->getConfigs();
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class TlogDestinationFile extends AbstractTlogDestination
|
|||||||
if (! is_dir($dir)) {
|
if (! is_dir($dir)) {
|
||||||
mkdir($dir, 0777, true);
|
mkdir($dir, 0777, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
touch($file_path);
|
touch($file_path);
|
||||||
chmod($file_path, 0777);
|
chmod($file_path, 0777);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class Tlog Implements LoggerInterface
|
|||||||
const ALERT = 700;
|
const ALERT = 700;
|
||||||
const EMERGENCY = 800;
|
const EMERGENCY = 800;
|
||||||
const MUET = PHP_INT_MAX;
|
const MUET = PHP_INT_MAX;
|
||||||
|
|
||||||
protected $levels = array(
|
protected $levels = array(
|
||||||
100 => "DEBUG",
|
100 => "DEBUG",
|
||||||
200 => "INFO",
|
200 => "INFO",
|
||||||
@@ -101,15 +101,16 @@ class Tlog Implements LoggerInterface
|
|||||||
public $dir_destinations = array();
|
public $dir_destinations = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function __construct(){}
|
private function __construct(){}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return \Thelia\Log\Tlog
|
* @return \Thelia\Log\Tlog
|
||||||
*/
|
*/
|
||||||
public static function getInstance() {
|
public static function getInstance()
|
||||||
|
{
|
||||||
if (self::$instance == false) {
|
if (self::$instance == false) {
|
||||||
self::$instance = new Tlog();
|
self::$instance = new Tlog();
|
||||||
|
|
||||||
@@ -149,7 +150,7 @@ class Tlog Implements LoggerInterface
|
|||||||
// -------------
|
// -------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string $destinations
|
* @param string $destinations
|
||||||
*/
|
*/
|
||||||
public function setDestinations($destinations)
|
public function setDestinations($destinations)
|
||||||
@@ -162,11 +163,11 @@ class Tlog Implements LoggerInterface
|
|||||||
$this->loadDestinations($this->destinations, $classes_destinations);
|
$this->loadDestinations($this->destinations, $classes_destinations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* change the debug level. Use Tlog constant : \Thelia\Log\Tlog::DEBUG set level to Debug
|
* change the debug level. Use Tlog constant : \Thelia\Log\Tlog::DEBUG set level to Debug
|
||||||
*
|
*
|
||||||
* @param int $level
|
* @param int $level
|
||||||
*/
|
*/
|
||||||
public function setLevel($level)
|
public function setLevel($level)
|
||||||
@@ -221,26 +222,26 @@ class Tlog Implements LoggerInterface
|
|||||||
/**
|
/**
|
||||||
* Detailed debug information.
|
* Detailed debug information.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function debug($message, array $context = array())
|
public function debug($message, array $context = array())
|
||||||
{
|
{
|
||||||
$this->log(self::DEBUG, $message, $context);
|
$this->log(self::DEBUG, $message, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Alias of debug method. With this method you can put all parameter you want
|
* Alias of debug method. With this method you can put all parameter you want
|
||||||
*
|
*
|
||||||
* ex : Tlog::getInstance()->addDebug($arg1, $arg2, $arg3);
|
* ex : Tlog::getInstance()->addDebug($arg1, $arg2, $arg3);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function addDebug()
|
public function addDebug()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
foreach ($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
$this->log(self::DEBUG, $arg);
|
$this->log(self::DEBUG, $arg);
|
||||||
}
|
}
|
||||||
@@ -251,54 +252,54 @@ class Tlog Implements LoggerInterface
|
|||||||
*
|
*
|
||||||
* Example: User logs in, SQL logs.
|
* Example: User logs in, SQL logs.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function info($message, array $context = array())
|
public function info($message, array $context = array())
|
||||||
{
|
{
|
||||||
$this->log(self::INFO, $message, $context);
|
$this->log(self::INFO, $message, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Alias of info method. With this method you can put all parameter you want
|
* Alias of info method. With this method you can put all parameter you want
|
||||||
*
|
*
|
||||||
* ex : Tlog::getInstance()->addInfo($arg1, $arg2, $arg3);
|
* ex : Tlog::getInstance()->addInfo($arg1, $arg2, $arg3);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function addInfo()
|
public function addInfo()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
foreach ($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
$this->log(self::INFO, $arg);
|
$this->log(self::INFO, $arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normal but significant events.
|
* Normal but significant events.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function notice($message, array $context = array())
|
public function notice($message, array $context = array())
|
||||||
{
|
{
|
||||||
$this->log(self::NOTICE, $message, $context);
|
$this->log(self::NOTICE, $message, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Alias of notice method. With this method you can put all parameter you want
|
* Alias of notice method. With this method you can put all parameter you want
|
||||||
*
|
*
|
||||||
* ex : Tlog::getInstance()->addNotice($arg1, $arg2, $arg3);
|
* ex : Tlog::getInstance()->addNotice($arg1, $arg2, $arg3);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function addNotice()
|
public function addNotice()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
foreach ($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
$this->log(self::NOTICE, $arg);
|
$this->log(self::NOTICE, $arg);
|
||||||
}
|
}
|
||||||
@@ -310,26 +311,26 @@ class Tlog Implements LoggerInterface
|
|||||||
* Example: Use of deprecated APIs, poor use of an API, undesirable things
|
* Example: Use of deprecated APIs, poor use of an API, undesirable things
|
||||||
* that are not necessarily wrong.
|
* that are not necessarily wrong.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function warning($message, array $context = array())
|
public function warning($message, array $context = array())
|
||||||
{
|
{
|
||||||
$this->log(self::WARNING, $message, $context);
|
$this->log(self::WARNING, $message, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Alias of warning method. With this method you can put all parameter you want
|
* Alias of warning method. With this method you can put all parameter you want
|
||||||
*
|
*
|
||||||
* ex : Tlog::getInstance()->addWarning($arg1, $arg2, $arg3);
|
* ex : Tlog::getInstance()->addWarning($arg1, $arg2, $arg3);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function addWarning()
|
public function addWarning()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
foreach ($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
$this->log(self::WARNING, $arg);
|
$this->log(self::WARNING, $arg);
|
||||||
}
|
}
|
||||||
@@ -339,154 +340,156 @@ class Tlog Implements LoggerInterface
|
|||||||
* Runtime errors that do not require immediate action but should typically
|
* Runtime errors that do not require immediate action but should typically
|
||||||
* be logged and monitored.
|
* be logged and monitored.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function error($message, array $context = array())
|
public function error($message, array $context = array())
|
||||||
{
|
{
|
||||||
$this->log(self::ERROR, $message, $context);
|
$this->log(self::ERROR, $message, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Alias of error method. With this method you can put all parameter you want
|
* Alias of error method. With this method you can put all parameter you want
|
||||||
*
|
*
|
||||||
* ex : Tlog::getInstance()->addError($arg1, $arg2, $arg3);
|
* ex : Tlog::getInstance()->addError($arg1, $arg2, $arg3);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function addError()
|
public function addError()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
foreach ($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
$this->log(self::ERROR, $arg);
|
$this->log(self::ERROR, $arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @see error()
|
* @see error()
|
||||||
*/
|
*/
|
||||||
public function err($message, array $context = array())
|
public function err($message, array $context = array())
|
||||||
{
|
{
|
||||||
$this->error($message, $context);
|
$this->error($message, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Critical conditions.
|
* Critical conditions.
|
||||||
*
|
*
|
||||||
* Example: Application component unavailable, unexpected exception.
|
* Example: Application component unavailable, unexpected exception.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function critical($message, array $context = array())
|
public function critical($message, array $context = array())
|
||||||
{
|
{
|
||||||
$this->log(self::CRITICAL, $message, $context);
|
$this->log(self::CRITICAL, $message, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Alias of critical method. With this method you can put all parameter you want
|
* Alias of critical method. With this method you can put all parameter you want
|
||||||
*
|
*
|
||||||
* ex : Tlog::getInstance()->addCritical($arg1, $arg2, $arg3);
|
* ex : Tlog::getInstance()->addCritical($arg1, $arg2, $arg3);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function addCritical()
|
public function addCritical()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
foreach ($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
$this->log(self::CRITICAL, $arg);
|
$this->log(self::CRITICAL, $arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @see critical()
|
* @see critical()
|
||||||
*/
|
*/
|
||||||
public function crit($message, array $context = array())
|
public function crit($message, array $context = array())
|
||||||
{
|
{
|
||||||
$this->critical($message, $context);
|
$this->critical($message, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action must be taken immediately.
|
* Action must be taken immediately.
|
||||||
*
|
*
|
||||||
* Example: Entire website down, database unavailable, etc. This should
|
* Example: Entire website down, database unavailable, etc. This should
|
||||||
* trigger the SMS alerts and wake you up.
|
* trigger the SMS alerts and wake you up.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function alert($message, array $context = array())
|
public function alert($message, array $context = array())
|
||||||
{
|
{
|
||||||
$this->log(self::ALERT, $message, $context);
|
$this->log(self::ALERT, $message, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Alias of alert method. With this method you can put all parameter you want
|
* Alias of alert method. With this method you can put all parameter you want
|
||||||
*
|
*
|
||||||
* ex : Tlog::getInstance()->addAlert($arg1, $arg2, $arg3);
|
* ex : Tlog::getInstance()->addAlert($arg1, $arg2, $arg3);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function addAlert()
|
public function addAlert()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
foreach ($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
$this->log(self::ALERT, $arg);
|
$this->log(self::ALERT, $arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System is unusable.
|
* System is unusable.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function emergency($message, array $context = array())
|
public function emergency($message, array $context = array())
|
||||||
{
|
{
|
||||||
$this->log(self::EMERGENCY, $message, $context);
|
$this->log(self::EMERGENCY, $message, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Alias of emergency method. With this method you can put all parameter you want
|
* Alias of emergency method. With this method you can put all parameter you want
|
||||||
*
|
*
|
||||||
* ex : Tlog::getInstance()->addEmergency($arg1, $arg2, $arg3);
|
* ex : Tlog::getInstance()->addEmergency($arg1, $arg2, $arg3);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function addEmergency()
|
public function addEmergency()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
|
||||||
foreach ($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
$this->log(self::EMERGENCY, $arg);
|
$this->log(self::EMERGENCY, $arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs with an arbitrary level.
|
* Logs with an arbitrary level.
|
||||||
*
|
*
|
||||||
* @param mixed $level
|
* @param mixed $level
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function log($level, $message, array $context = array()) {
|
public function log($level, $message, array $context = array())
|
||||||
|
{
|
||||||
if($this->level > $level || array_key_exists($level, $this->levels) === false)
|
if($this->level > $level || array_key_exists($level, $this->levels) === false)
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$this->out($this->levels[$level], $message, $context);
|
$this->out($this->levels[$level], $message, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Mode back office
|
// Mode back office
|
||||||
public static function SetBackOfficeMode($booleen)
|
public static function SetBackOfficeMode($booleen)
|
||||||
@@ -497,10 +500,10 @@ class Tlog Implements LoggerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* final end method. Write log for each destination handler
|
* final end method. Write log for each destination handler
|
||||||
*
|
*
|
||||||
* @param string $res
|
* @param string $res
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function write(&$res)
|
public function write(&$res)
|
||||||
@@ -550,10 +553,10 @@ class Tlog Implements LoggerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* check if level is activated and control if current file is activated
|
* check if level is activated and control if current file is activated
|
||||||
*
|
*
|
||||||
* @param int $level
|
* @param int $level
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isActivated($level)
|
public function isActivated($level)
|
||||||
@@ -571,12 +574,12 @@ class Tlog Implements LoggerInterface
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* check if $file is in authorized files
|
* check if $file is in authorized files
|
||||||
*
|
*
|
||||||
* @param string $file
|
* @param string $file
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isActivedFile($file)
|
public function isActivedFile($file)
|
||||||
@@ -586,7 +589,6 @@ class Tlog Implements LoggerInterface
|
|||||||
|
|
||||||
/* -- Methodes privees ---------------------------------------- */
|
/* -- Methodes privees ---------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
private function findOrigin()
|
private function findOrigin()
|
||||||
{
|
{
|
||||||
$origine = array();
|
$origine = array();
|
||||||
@@ -629,7 +631,7 @@ class Tlog Implements LoggerInterface
|
|||||||
|
|
||||||
return $origine;
|
return $origine;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function interpolate($message, array $context = array())
|
protected function interpolate($message, array $context = array())
|
||||||
{
|
{
|
||||||
// build a replacement array with braces around the context keys
|
// build a replacement array with braces around the context keys
|
||||||
@@ -645,7 +647,7 @@ class Tlog Implements LoggerInterface
|
|||||||
private function out($level, $message, array $context = array())
|
private function out($level, $message, array $context = array())
|
||||||
{
|
{
|
||||||
$text = '';
|
$text = '';
|
||||||
|
|
||||||
/*if (is_array($message)) {
|
/*if (is_array($message)) {
|
||||||
foreach ($message as $arg) {
|
foreach ($message as $arg) {
|
||||||
$text .= is_scalar($arg) ? $arg : print_r($arg, true);
|
$text .= is_scalar($arg) ? $arg : print_r($arg, true);
|
||||||
@@ -655,7 +657,7 @@ class Tlog Implements LoggerInterface
|
|||||||
} else {
|
} else {
|
||||||
$text = $message;
|
$text = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
$text = $this->interpolate($text, $context);
|
$text = $this->interpolate($text, $context);
|
||||||
|
|
||||||
$origine = $this->findOrigin();
|
$origine = $this->findOrigin();
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
namespace Thelia\Log;
|
namespace Thelia\Log;
|
||||||
|
|
||||||
use Thelia\Model\Config;
|
use Thelia\Model\Config;
|
||||||
use Thelia\Model\ConfigDesc;
|
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
|
|
||||||
class TlogDestinationConfig
|
class TlogDestinationConfig
|
||||||
@@ -51,11 +50,9 @@ class TlogDestinationConfig
|
|||||||
$this->load();
|
$this->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function load()
|
public function load()
|
||||||
{
|
{
|
||||||
if (null === $config = ConfigQuery::create()->findOneByName($this->name))
|
if (null === $config = ConfigQuery::create()->findOneByName($this->name)) {
|
||||||
{
|
|
||||||
$config = new Config();
|
$config = new Config();
|
||||||
$config->setName($this->name);
|
$config->setName($this->name);
|
||||||
$config->setValue($this->default);
|
$config->setValue($this->default);
|
||||||
@@ -63,7 +60,7 @@ class TlogDestinationConfig
|
|||||||
$config->setSecured(1);
|
$config->setSecured(1);
|
||||||
$config->save();
|
$config->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->value = $config->getValue();
|
$this->value = $config->getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user