apply cs-fixer

This commit is contained in:
Manuel Raynaud
2013-08-14 09:29:04 +02:00
parent a3fcb222be
commit 078b1e0d57
125 changed files with 1339 additions and 1491 deletions

View File

@@ -22,15 +22,12 @@
/*************************************************************************************/
namespace Thelia\Action;
use Thelia\Form\BaseForm;
use Thelia\Action\Exception\FormValidationException;
use Thelia\Core\Event\ActionEvent;
use Symfony\Component\Form\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
class BaseAction
{
@@ -39,16 +36,17 @@ class BaseAction
*/
protected $container;
public function __construct(ContainerInterface $container) {
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* Validate a BaseForm
*
* @param BaseForm $aBaseForm the form
* @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
* @param BaseForm $aBaseForm the form
* @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
* @return \Symfony\Component\Form\Form Form the symfony form object
*/
protected function validateForm(BaseForm $aBaseForm, $expectedMethod = null)
@@ -60,14 +58,11 @@ class BaseAction
$form->bind($aBaseForm->getRequest());
if ($form->isValid()) {
return $form;
}
else {
} else {
throw new FormValidationException("Missing or invalid data");
}
}
else {
} else {
throw new FormValidationException(sprintf("Wrong form method, %s expected.", $expectedMethod));
}
}
@@ -75,12 +70,12 @@ class BaseAction
/**
* Propagate a form error in the action event
*
* @param BaseForm $aBaseForm the form
* @param string $error_message an error message that may be displayed to the customer
* @param ActionEvent $event the action event
* @param BaseForm $aBaseForm the form
* @param string $error_message an error message that may be displayed to the customer
* @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
$aBaseForm->setError(true);
$aBaseForm->setErrorMessage($error_message);
@@ -102,4 +97,4 @@ class BaseAction
return $this->container->get('event_dispatcher');
}
}
}

View File

@@ -25,10 +25,8 @@ namespace Thelia\Action;
use Propel\Runtime\Exception\PropelException;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\CartEvent;
use Thelia\Form\CartAdd;
use Thelia\Model\ProductPrice;
@@ -92,14 +90,13 @@ class Cart extends BaseAction implements EventSubscriberInterface
$message = $e->getMessage();
}
if($message) {
if ($message) {
// The form has errors, propagate it.
$this->propagateFormError($cartAdd, $message, $event);
}
}
/**
*
* Delete specify article present into cart
@@ -184,13 +181,11 @@ class Cart extends BaseAction implements EventSubscriberInterface
);
}
/**
* increase the quantity for an existing cartItem
*
* @param CartItem $cartItem
* @param float $quantity
* @param float $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
*
* @param \Thelia\Model\Cart $cart
* @param int $productId
* @param int $productSaleElementsId
* @param float $quantity
* @param ProductPrice $productPrice
* @param int $productId
* @param int $productSaleElementsId
* @param float $quantity
* @param 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
* and the product_sale_elements id
*
* @param int $cartId
* @param int $productId
* @param int $productSaleElementsId
* @param int $cartId
* @param int $productId
* @param int $productSaleElementsId
* @return ChildCartItem
*/
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
*
* @param Request $request
* @param Request $request
* @return CartAdd
*/
private function getAddCartForm(Request $request)

View File

@@ -40,15 +40,14 @@ use Propel\Runtime\Propel;
use Thelia\Model\Map\CategoryTableMap;
use Propel\Runtime\Exception\PropelException;
class Category extends BaseAction implements EventSubscriberInterface
{
public function create(ActionEvent $event)
{
$this->checkAuth("ADMIN", "admin.category.create");
$this->checkAuth("ADMIN", "admin.category.create");
$request = $event->getRequest();
$request = $event->getRequest();
try {
$categoryCreationForm = new CategoryCreationForm($request);
@@ -92,7 +91,7 @@ class Category extends BaseAction implements EventSubscriberInterface
public function modify(ActionEvent $event)
{
$this->checkAuth("ADMIN", "admin.category.delete");
$this->checkAuth("ADMIN", "admin.category.delete");
$request = $event->getRequest();
@@ -163,9 +162,9 @@ class Category extends BaseAction implements EventSubscriberInterface
public function delete(ActionEvent $event)
{
$this->checkAuth("ADMIN", "admin.category.delete");
$this->checkAuth("ADMIN", "admin.category.delete");
$request = $event->getRequest();
$request = $event->getRequest();
try {
$categoryDeletionForm = new CategoryDeletionForm($request);
@@ -214,11 +213,11 @@ class Category extends BaseAction implements EventSubscriberInterface
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) {
@@ -237,8 +236,9 @@ class Category extends BaseAction implements EventSubscriberInterface
*
* @param ActionEvent $event
*/
public function changePositionUp(ActionEvent $event) {
return $this->exchangePosition($event, 'up');
public function changePositionUp(ActionEvent $event)
{
return $this->exchangePosition($event, 'up');
}
/**
@@ -246,67 +246,65 @@ class Category extends BaseAction implements EventSubscriberInterface
*
* @param ActionEvent $event
*/
public function changePositionDown(ActionEvent $event) {
return $this->exchangePosition($event, 'down');
public function changePositionDown(ActionEvent $event)
{
return $this->exchangePosition($event, 'down');
}
/**
* Move up or down a category
*
* @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
$my_position = $category->getPosition();
// Find category to exchange position with
$search = CategoryQuery::create()
->filterByParent($category->getParent());
// Find category to exchange position with
$search = CategoryQuery::create()
->filterByParent($category->getParent());
// Up or down ?
if ($direction == 'up') {
// 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 ?
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;
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
if ($result) {
$cnx = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME);
$cnx = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME);
$cnx->beginTransaction();
$cnx->beginTransaction();
try {
$category->setPosition($result->getPosition())->save();
try {
$category->setPosition($result->getPosition())->save();
$result->setPosition($my_position)->save();
$result->setPosition($my_position)->save();
$cnx->commit();
}
catch(Exception $e) {
$cnx->rollback();
}
}
}
$cnx->commit();
} catch (Exception $e) {
$cnx->rollback();
}
}
}
}
/**
@@ -314,61 +312,59 @@ class Category extends BaseAction implements EventSubscriberInterface
*
* @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
$new_position = $request->get('position', null);
// The current position
$current_position = $category->getPosition();
// The current position
$current_position = $category->getPosition();
if ($new_position != null && $new_position > 0 && $new_position != $current_position) {
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
$search = CategoryQuery::create()->filterByParent($category->getParent());
if ($new_position > $current_position) {
// 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) {
// 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));
$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;
}
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;
}
$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 {
foreach($results as $result) {
$result->setPosition($result->getPosition() + $delta)->save($cnx);
}
$category->setPosition($new_position)->save($cnx);
$category->setPosition($new_position)->save($cnx);
$cnx->commit();
}
catch(Exception $e) {
$cnx->rollback();
}
}
}
}
$cnx->commit();
} catch (Exception $e) {
$cnx->rollback();
}
}
}
}
/**
* Returns an array of event names this subscriber listens to.

View File

@@ -26,7 +26,6 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\BaseForm;
use Thelia\Form\CustomerCreation;
use Thelia\Form\CustomerModification;
use Thelia\Model\Customer as CustomerModel;
@@ -34,7 +33,6 @@ use Thelia\Log\Tlog;
use Thelia\Model\CustomerQuery;
use Thelia\Form\CustomerLogin;
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
use Thelia\Core\Security\SecurityContext;
use Symfony\Component\Validator\Exception\ValidatorException;
use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Core\Security\Exception\UsernameNotFoundException;
@@ -122,7 +120,6 @@ class Customer extends BaseAction implements EventSubscriberInterface
$this->processSuccessfullLogin($event, $customer, $customerModification);
} catch (PropelException $e) {
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.";
@@ -144,8 +141,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
{
$event->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_LOGOUT, $event);
$this->getFrontSecurityContext()->clear();
$this->getFrontSecurityContext()->clear();
}
/**