This commit is contained in:
Manuel Raynaud
2013-10-25 10:07:21 +02:00
parent 22caf28f80
commit 2c030f910b
91 changed files with 219 additions and 761 deletions

View File

@@ -56,7 +56,7 @@ abstract class AbstractCrudController extends BaseAdminController
* @param string $defaultListOrder the default object list order, or null if list is not sortable. Example: manual
* @param string $orderRequestParameterName Name of the request parameter that set the list order (null if list is not sortable)
*
* @param string $resourceCode the 'resource' code. Example: "admin.configuration.message"
* @param string $resourceCode the 'resource' code. Example: "admin.configuration.message"
*
* @param string $createEventIdentifier the dispatched create TheliaEvent identifier. Example: TheliaEvents::MESSAGE_CREATE
* @param string $updateEventIdentifier the dispatched update TheliaEvent identifier. Example: TheliaEvents::MESSAGE_UPDATE

View File

@@ -23,7 +23,6 @@
namespace Thelia\Controller\Admin;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Event\Administrator\AdministratorEvent;
use Thelia\Core\Event\TheliaEvents;
@@ -31,7 +30,6 @@ use Thelia\Form\AdministratorCreationForm;
use Thelia\Form\AdministratorModificationForm;
use Thelia\Model\AdminQuery;
class AdministratorController extends AbstractCrudController
{
public function __construct()
@@ -158,7 +156,6 @@ class AdministratorController extends AbstractCrudController
return $object->getId();
}
protected function renderListTemplate($currentOrder)
{
// We always return to the feature edition form
@@ -198,4 +195,4 @@ class AdministratorController extends AbstractCrudController
"admin.configuration.administrators.view"
);
}
}
}

View File

@@ -115,7 +115,7 @@ class BaseAdminController extends BaseController
* Check current admin user authorisations. An ADMIN role is assumed.
*
* @param mixed $resources a single resource or an array of resources.
* @param mixed $accesses a single access or an array of accesses.
* @param mixed $accesses a single access or an array of accesses.
*
* @return mixed null if authorization is granted, or a Response object which contains the error page otherwise
*
@@ -369,8 +369,8 @@ class BaseAdminController extends BaseController
* Render the given template, and returns the result as an Http Response.
*
* @param $templateName the complete template name, with extension
* @param array $args the template arguments
* @param int $status http code status
* @param array $args the template arguments
* @param int $status http code status
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function render($templateName, $args = array(), $status = 200)

View File

@@ -25,7 +25,6 @@ namespace Thelia\Controller\Admin;
use Propel\Runtime\Exception\PropelException;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Event\Customer\CustomerAddressEvent;
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\Customer\CustomerEvent;
use Thelia\Core\Event\TheliaEvents;

View File

@@ -41,7 +41,6 @@ use Thelia\Form\Lang\LangUrlForm;
use Thelia\Model\ConfigQuery;
use Thelia\Model\LangQuery;
/**
* Class LangController
* @package Thelia\Controller\Admin
@@ -53,7 +52,6 @@ class LangController extends BaseAdminController
public function defaultAction()
{
if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::VIEW)) return $response;
return $this->renderDefault();
}
@@ -120,7 +118,7 @@ class LangController extends BaseAdminController
$changedObject = $event->getLang();
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", 'Lang', $changedObject->getTitle(), $changedObject->getId()));
$this->redirectToRoute('/admin/configuration/languages');
} catch(\Exception $e) {
} catch (\Exception $e) {
$error_msg = $e->getMessage();
}
@@ -162,7 +160,7 @@ class LangController extends BaseAdminController
$error = $e->getMessage();
}
if($error) {
if ($error) {
return $this->nullResponse(500);
} else {
return $this->nullResponse();
@@ -281,7 +279,7 @@ class LangController extends BaseAdminController
$event = new LangUrlEvent();
foreach ($data as $key => $value) {
$pos= strpos($key, LangUrlForm::LANG_PREFIX);
if(false !== strpos($key, LangUrlForm::LANG_PREFIX)) {
if (false !== strpos($key, LangUrlForm::LANG_PREFIX)) {
$event->addUrl(substr($key,strlen(LangUrlForm::LANG_PREFIX)), $value);
}
}
@@ -326,4 +324,4 @@ class LangController extends BaseAdminController
$this->redirectToRoute('admin.configuration.languages');
}
}
}

View File

@@ -38,5 +38,5 @@ class LanguageController extends BaseAdminController
if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::VIEW)) return $response;
return $this->render("languages");
}
}
}

View File

@@ -38,5 +38,5 @@ class MailingSystemController extends BaseAdminController
if (null !== $response = $this->checkAuth(AdminResources::MAILING_SYSTEM, AccessManager::VIEW)) return $response;
return $this->render("mailing-system");
}
}
}

View File

@@ -47,7 +47,6 @@ class MessageController extends AbstractCrudController
AdminResources::MESSAGE,
TheliaEvents::MESSAGE_CREATE,
TheliaEvents::MESSAGE_UPDATE,
TheliaEvents::MESSAGE_DELETE,

View File

@@ -41,7 +41,7 @@ class ModuleController extends BaseAdminController
public function indexAction()
{
if (null !== $response = $this->checkAuth(AdminResources::MODULE, AccessManager::VIEW)) return $response;
$modulemanagement = new ModuleManagement();
$modulemanagement->updateModules();
@@ -100,7 +100,7 @@ class ModuleController extends BaseAdminController
$this->dispatch(TheliaEvents::MODULE_DELETE, $deleteEvent);
if($deleteEvent->hasModule() === false) {
if ($deleteEvent->hasModule() === false) {
throw new \LogicException(
$this->getTranslator()->trans("No %obj was updated.", array('%obj' => 'Module')));
}
@@ -110,7 +110,7 @@ class ModuleController extends BaseAdminController
$message = $e->getMessage();
}
if($message) {
if ($message) {
return $this->render("modules", array(
"error_message" => $message
));

View File

@@ -54,7 +54,6 @@ use Thelia\Core\Event\ProductSaleElement\ProductSaleElementCreateEvent;
use Thelia\Model\AttributeQuery;
use Thelia\Model\AttributeAvQuery;
use Thelia\Form\ProductSaleElementUpdateForm;
use Thelia\Model\ProductSaleElements;
use Thelia\Model\ProductPriceQuery;
use Thelia\Form\ProductDefaultSaleElementUpdateForm;
use Thelia\Model\ProductPrice;
@@ -62,8 +61,6 @@ use Thelia\Model\Currency;
use Symfony\Component\HttpFoundation\JsonResponse;
use Thelia\TaxEngine\Calculator;
use Thelia\Model\Country;
use Thelia\Model\CountryQuery;
use Thelia\Model\TaxRuleQuery;
use Thelia\Tools\NumberFormat;
use Thelia\Model\Product;
use Thelia\Model\CurrencyQuery;
@@ -189,8 +186,8 @@ class ProductController extends AbstractCrudController
return $event->hasProduct();
}
protected function updatePriceFromDefaultCurrency($productPrice, $saleElement, $defaultCurrency, $currentCurrency) {
protected function updatePriceFromDefaultCurrency($productPrice, $saleElement, $defaultCurrency, $currentCurrency)
{
// Get price for default currency
$priceForDefaultCurrency = ProductPriceQuery::create()
->filterByCurrency($defaultCurrency)
@@ -206,7 +203,8 @@ class ProductController extends AbstractCrudController
}
}
protected function appendValue(&$array, $key, $value) {
protected function appendValue(&$array, $key, $value)
{
if (! isset($array[$key])) $array[$key] = array();
$array[$key][] = $value;
@@ -228,7 +226,7 @@ class ProductController extends AbstractCrudController
"tax_rule" => $object->getTaxRuleId()
);
foreach($saleElements as $saleElement) {
foreach ($saleElements as $saleElement) {
// Get the product price for the current currency
$productPrice = ProductPriceQuery::create()
@@ -277,8 +275,7 @@ class ProductController extends AbstractCrudController
"isdefault" => $saleElement->getIsDefault() > 0 ? 1 : 0,
"ean_code" => $saleElement->getEanCode()
);
}
else {
} else {
if ($saleElement->getIsDefault()) {
$combinationPseData['default_pse'] = $saleElement->getId();
@@ -871,8 +868,7 @@ class ProductController extends AbstractCrudController
try {
$this->dispatch(TheliaEvents::PRODUCT_ADD_PRODUCT_SALE_ELEMENT, $event);
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
@@ -895,8 +891,7 @@ class ProductController extends AbstractCrudController
try {
$this->dispatch(TheliaEvents::PRODUCT_DELETE_PRODUCT_SALE_ELEMENT, $event);
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
@@ -907,7 +902,7 @@ class ProductController extends AbstractCrudController
/**
* Process a single PSE update, using form data array.
*
* @param array $data the form data
* @param array $data the form data
* @throws Exception is someting goes wrong.
*/
protected function processSingleProductSaleElementUpdate($data)
@@ -969,7 +964,7 @@ class ProductController extends AbstractCrudController
$count = count($data['product_sale_element_id']);
for($idx = 0; $idx < $count; $idx++) {
for ($idx = 0; $idx < $count; $idx++) {
$tmp_data['product_sale_element_id'] = $pse_id = $data['product_sale_element_id'][$idx];
$tmp_data['reference'] = $data['reference'][$idx];
$tmp_data['price'] = $data['price'][$idx];
@@ -983,8 +978,7 @@ class ProductController extends AbstractCrudController
$this->processSingleProductSaleElementUpdate($tmp_data);
}
}
else {
} else {
// No need to preprocess data
$this->processSingleProductSaleElementUpdate($data);
}
@@ -996,12 +990,10 @@ class ProductController extends AbstractCrudController
// Redirect to the success URL
$this->redirect($changeForm->getSuccessUrl());
}
catch (FormValidationException $ex) {
} catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
@@ -1016,7 +1008,8 @@ class ProductController extends AbstractCrudController
/**
* Process the change of product's PSE list.
*/
public function updateProductSaleElementsAction() {
public function updateProductSaleElementsAction()
{
return $this->processProductSaleElementUpdate(
new ProductSaleElementUpdateForm($this->getRequest())
);
@@ -1025,7 +1018,8 @@ class ProductController extends AbstractCrudController
/**
* Update default product sale element (not attached to any combination)
*/
public function updateProductDefaultSaleElementAction() {
public function updateProductDefaultSaleElementAction()
{
return $this->processProductSaleElementUpdate(
new ProductDefaultSaleElementUpdateForm($this->getRequest())
);
@@ -1035,8 +1029,8 @@ class ProductController extends AbstractCrudController
* Invoked through Ajax; this method calculates the taxed price from the unaxed price, and
* vice versa.
*/
public function priceCaclulator() {
public function priceCaclulator()
{
$return_price = 0;
$price = floatval($this->getRequest()->get('price', 0));
@@ -1048,11 +1042,9 @@ class ProductController extends AbstractCrudController
if ($action == 'to_tax') {
$return_price = $this->computePrice($price, 'without_tax', $product);
}
else if ($action == 'from_tax') {
} elseif ($action == 'from_tax') {
$return_price = $this->computePrice($price, 'with_tax', $product);
}
else {
} else {
$return_price = $price;
}
@@ -1069,8 +1061,8 @@ class ProductController extends AbstractCrudController
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function loadConvertedPrices() {
public function loadConvertedPrices()
{
$product_sale_element_id = intval($this->getRequest()->get('product_sale_element_id', 0));
$currency_id = intval($this->getRequest()->get('currency_id', 0));
@@ -1114,13 +1106,13 @@ class ProductController extends AbstractCrudController
/**
* Calculate taxed/untexted price for a product
*
* @param unknown $price
* @param unknown $price_type
* @param Product $product
* @param unknown $price
* @param unknown $price_type
* @param Product $product
* @return Ambigous <unknown, number>
*/
protected function computePrice($price, $price_type, Product $product, $convert = false) {
protected function computePrice($price, $price_type, Product $product, $convert = false)
{
$calc = new Calculator();
$calc->load(
@@ -1130,11 +1122,9 @@ class ProductController extends AbstractCrudController
if ($price_type == 'without_tax') {
$return_price = $calc->getTaxedPrice($price);
}
else if ($price_type == 'with_tax') {
} elseif ($price_type == 'with_tax') {
$return_price = $calc->getUntaxedPrice($price);
}
else {
} else {
$return_price = $price;
}

View File

@@ -29,7 +29,6 @@ use Thelia\Core\Event\Profile\ProfileEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\ProfileCreationForm;
use Thelia\Form\ProfileModificationForm;
use Thelia\Form\ProfileProfileListUpdateForm;
use Thelia\Form\ProfileUpdateModuleAccessForm;
use Thelia\Form\ProfileUpdateResourceAccessForm;
use Thelia\Model\ProfileQuery;
@@ -201,8 +200,8 @@ class ProfileController extends AbstractCrudController
/**
* Put in this method post object creation processing if required.
*
* @param ProfileEvent $createEvent the create event
* @return Response a response, or null to continue normal processing
* @param ProfileEvent $createEvent the create event
* @return Response a response, or null to continue normal processing
*/
protected function performAdditionalCreateAction($createEvent)
{
@@ -263,8 +262,8 @@ class ProfileController extends AbstractCrudController
protected function getResourceAccess($formData)
{
$requirements = array();
foreach($formData as $data => $value) {
if(!strstr($data, ':')) {
foreach ($formData as $data => $value) {
if (!strstr($data, ':')) {
continue;
}
@@ -272,7 +271,7 @@ class ProfileController extends AbstractCrudController
$prefix = array_shift ( $explosion );
if($prefix != ProfileUpdateResourceAccessForm::RESOURCE_ACCESS_FIELD_PREFIX) {
if ($prefix != ProfileUpdateResourceAccessForm::RESOURCE_ACCESS_FIELD_PREFIX) {
continue;
}
@@ -285,8 +284,8 @@ class ProfileController extends AbstractCrudController
protected function getModuleAccess($formData)
{
$requirements = array();
foreach($formData as $data => $value) {
if(!strstr($data, ':')) {
foreach ($formData as $data => $value) {
if (!strstr($data, ':')) {
continue;
}
@@ -294,7 +293,7 @@ class ProfileController extends AbstractCrudController
$prefix = array_shift ( $explosion );
if($prefix != ProfileUpdateModuleAccessForm::MODULE_ACCESS_FIELD_PREFIX) {
if ($prefix != ProfileUpdateModuleAccessForm::MODULE_ACCESS_FIELD_PREFIX) {
continue;
}
@@ -401,4 +400,4 @@ class ProfileController extends AbstractCrudController
// At this point, the form has errors, and should be redisplayed.
return $this->renderEditionTemplate();
}
}
}

View File

@@ -28,7 +28,6 @@ use Thelia\Core\Event\Tax\TaxEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\TaxCreationForm;
use Thelia\Form\TaxModificationForm;
use Thelia\Form\TaxTaxListUpdateForm;
use Thelia\Model\TaxQuery;
class TaxController extends AbstractCrudController
@@ -177,7 +176,7 @@ class TaxController extends AbstractCrudController
/**
* Put in this method post object creation processing if required.
*
* @param TaxEvent $createEvent the create event
* @param TaxEvent $createEvent the create event
* @return Response a response, or null to continue normal processing
*/
protected function performAdditionalCreateAction($createEvent)
@@ -200,20 +199,19 @@ class TaxController extends AbstractCrudController
{
$type = $formData['type'];
}
protected function getRequirements($type, $formData)
{
$requirements = array();
foreach($formData as $data => $value) {
if(!strstr($data, ':')) {
foreach ($formData as $data => $value) {
if (!strstr($data, ':')) {
continue;
}
$couple = explode(':', $data);
if(count($couple) != 2 || $couple[0] != $type) {
if (count($couple) != 2 || $couple[0] != $type) {
continue;
}
@@ -222,4 +220,4 @@ class TaxController extends AbstractCrudController
return $requirements;
}
}
}